【发布时间】:2011-11-22 07:14:19
【问题描述】:
我在 global.asax 中有以下代码:
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
if (Request.Cookies["AUTH"] != null)
{
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(Request.Cookies["AUTH"].Value);
HttpContext.Current.User = new MyPrincipal(ticket.Name);
HttpCookie cookie = Request.Cookies["AUTH"];
cookie.Expires = DateTime.Now.AddDays(30);
Response.Cookies.Add(cookie);
}
}
它工作正常,但是当我检查 Request.Cookies 集合时,有 2 个 AUTH cookie 条目,具有不同的值。怎么会?
这是登录页面中认证过程的代码:
if (Account.Authenticate(login.Text, pass.Text))
{
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(login.Text, true, 43200);
HttpCookie cookie = new HttpCookie("AUTH");
cookie.Expires = DateTime.Now.AddDays(30);
cookie.HttpOnly = true;
cookie.Value = FormsAuthentication.Encrypt(ticket);
Response.Cookies.Add(cookie);
Response.Redirect(Page.Request.UrlReferrer.ToString());
}
【问题讨论】:
标签: asp.net authentication cookies