English 中文(简体)
2. 未经查询便使用厨师的蚊帐接口之间的转导
原标题:redirection between asp .net interfaces using cookies without querystring

I have two asp .net interfaces:

  1. app1.domain.com
  2. app2.domain.com

In default page of both, there is a link button from which we can switch between them. Previously we use query strings to pass username and password. But now we want to use cookies. So in click event of link button, I have code like this:

    HttpCookie cookie = new HttpCookie("MYCookie", Guid.NewGuid().ToString());
    cookie.Domain = "domain.com";
    cookie.Expires = DateTime.UtcNow.AddHours(1);
    cookie.HttpOnly = false;
    cookie.Secure = true;

    cookie.Values.Add("Username", Username.ToString());
    cookie.Values.Add("UserId", UserId.ToString());
    Response.Cookies.Add(cookie);
    Response.Redirect(destinationAddress);

如今,在其他申请的缺席网页上,读写成:

    protected override void InitializeCulture() {
     if (Request.Cookies["MYCookie"] != null) {
       HttpCookie cookie = null;
      cookie = Request.Cookies.Get("MYCookie");
         }
      }

但这里是请求。 库克群岛认为“MYCookie”是无效的。 什么是失踪? 请提出咨询意见。

问题回答

我认为,问题就属于你的职权范围。

改动cookie.Domain = “domain”; to be cookie. 域 = “.domain.com”;

我认为,你需要增加HttpCookie的同一道路财产,用于 app1和 app2。

Response.Redirect generates ThreadAbortException. All the changes made in your cookie will be lost. so you can use,

<meta http-equiv="Refresh" content="10; URL=your url" />

c 代码:

System.Web.UI.HtmlControls.HtmlMeta meta = new System.Web.UI.HtmlControls.HtmlMeta();
meta.HttpEquiv = "Refresh";
meta.Content = "10; URL=your url";
Page.Header.Controls.Add(meta);

并且把你 co成像

cookie.Domain = ".domain.com";




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签