找不到表单验证的cookie
本文关键字:cookie 验证 表单 找不到 | 更新日期: 2023-09-27 18:03:35
我有两个页面登录。asp和cookie.aspx
当用户登录时,应该创建一个cookie并重定向到cookie.aspx。当饼干。Aspx加载它来检查cookie是否存在。
这是我的登录名。Aspx登录码
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
userName = Login1.UserName;
passWord = Login1.Password;
athUser = DirectoryServicesProcessor.Verify_User(userName, passWord);
if (athUser == true)
{
//FormsAuthentication.SetAuthCookie(userName, false);
bool IsPersistentCookie = true;
DateTime expirationDate = new DateTime();
if (IsPersistentCookie)
expirationDate = DateTime.Now.AddYears(1);
else
expirationDate = DateTime.Now.AddMinutes(300);
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
userName,
DateTime.Now,
expirationDate,
IsPersistentCookie,
userName,
FormsAuthentication.FormsCookiePath);
string et = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, et);
if (IsPersistentCookie)
cookie.Expires = ticket.Expiration;
cookie.Name = ".AUTH";
cookie.Domain = ".mydomain.com";
Response.SetCookie(cookie);
Response.Cookies.Add(cookie);
Response.Redirect("~/cookietest/cookie.aspx");
}
这是我的cookie.aspx的页面加载
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(FormsAuthentication.FormsCookieName);
if (cookie != null)
{
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);
if (ticket != null)
{
WhatHappened.Text = "Found the cookie!";
}
else
{
Response.Redirect("../failure.aspx");
}
}
else
{
Response.Redirect("../failure.aspx");
}
}
我想知道为什么饼干。
谢谢!
我将使用FormsAuthentication.FormsCookieName
设置cookie名称。
cookie.Name = FormsAuthentication.FormsCookieName;
对我来说,设置为.ASPXAUTH
而不是.AUTH
。