【发布时间】:2011-02-03 01:31:00
【问题描述】:
这是我登录成功时调用的函数。 (我对 FormAuthentication 这个东西很陌生)
public static void CreateLoginCookie(User u)
{
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(u.Id.ToString(), true, 9*60);
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket) { Expires = DateTime.Now.AddHours(9) };
HttpContext.Current.Response.Cookies.Add(cookie);
}
在 web.config 我有
<authentication mode="Forms">
<forms loginUrl="~/Default/Login" timeout="540" />
</authentication>
我希望用户保持登录状态 9 小时,但它不起作用。他们会在一两个小时后退出。
谁能告诉我我错过了什么?
【问题讨论】:
-
您确定是票证而不是会话到期吗?
标签: c# asp.net forms-authentication