【发布时间】:2011-07-05 06:19:15
【问题描述】:
我在共享主机上部署了 asp.net mvc 3 站点。我的问题是我的网站经常在 5 到 10 分钟后自动注销用户。虽然我在 web.config 和 application_start 中将时间设置为 200 分钟,如下所示
<forms loginUrl="~/Account.mvc/index" slidingExpiration="true" timeout="200" protection="All" />
HttpCookie authCookie = FormsAuthentication.GetAuthCookie(userName, rememberMe);
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
FormsAuthenticationTicket newTicket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddMinutes(200), rememberMe, CurrentUser.UserID +"|"+ CurrentUser.EmployeeID);
authCookie.Value = FormsAuthentication.Encrypt(newTicket);
Response.Cookies.Add(authCookie);
【问题讨论】:
-
你在哪里设置这个
FormsAuthenticationTicket?你在使用会话吗? -
我正在使用 cookie,如我编辑的问题所示
-
您在哪里使用此代码?为什么要重新发送身份验证 cookie?
-
实际上,当我更新我的答案时,我在 cookie 中保存了额外的信息
标签: asp.net-mvc asp.net-mvc-3 asp.net-membership membership-provider