这是一个MVC2网站,我有FormsAuthentication票证的问题。 30分钟后用户超时无法重新登录。在测试过程中,DateTime.Now.AddMinutes(30)值设置为5000,一切正常,但现在已更改为30,这就是问题开始的时间
从cookie创建
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
user.UserID,
DateTime.Now,
DateTime.Now.AddMinutes(30),
false,
"user,user1",
FormsAuthentication.FormsCookiePath);
Web.config文件
<authentication mode="Forms">
<forms loginUrl="~/Account.mvc/LogOn" timeout="2880" name=".ASPXFORMSAUTH" />
</authentication>
凭单创建中的到期值是否需要> = web.config值?
最佳答案
因为您是手动创建身份验证cookie,所以web.config中的超时值将被完全忽略。因此,我建议您使用相同的值:
var ticket = new FormsAuthenticationTicket(
1,
user.UserID,
DateTime.Now,
DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes),
false,
"user,user1",
FormsAuthentication.FormsCookiePath
);
var encryptedTicket = FormsAuthentication.Encrypt(ticket);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
{
HttpOnly = true,
Secure = FormsAuthentication.RequireSSL,
Path = FormsAuthentication.FormsCookiePath,
Domain = FormsAuthentication.CookieDomain
};
Response.AppendCookie(cookie);