【发布时间】:2010-06-11 20:20:27
【问题描述】:
我有一个使用 Forms Auth 的网站。客户端根本不希望用户的站点会话过期。在登录页面代码隐藏中,使用了以下代码:
// user passed validation
FormsAuthentication.Initialize();
// grab the user's roles out of the database
String strRole = AssignRoles(UserName.Text);
// creates forms auth ticket with expiration date of 100 years from now and make it persistent
FormsAuthenticationTicket fat = new FormsAuthenticationTicket(1,
UserName.Text, DateTime.Now,
DateTime.Now.AddYears(100), true, strRole,
FormsAuthentication.FormsCookiePath);
// create a cookie and throw the ticket in there, set expiration date to 100 years from now
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,
FormsAuthentication.Encrypt(fat)) { Expires = DateTime.Now.AddYears(100) };
// add the cookie to the response queue
Response.Cookies.Add(cookie);
Response.Redirect(FormsAuthentication.GetRedirectUrl(UserName.Text, false));
web.config 文件的身份验证部分如下所示:
<authentication mode="Forms">
<forms name="APLOnlineCompliance" loginUrl="~/Login.aspx" defaultUrl="~/Course/CourseViewer.aspx" />
</authentication>
当我登录网站时,我会 see 正确发送 cookie 到浏览器并传回:
HttpFox output http://cid-e79f8e4b07c3e30f.office.live.com/embedphoto.aspx/Public/SessionProblem.png
但是,当我离开 20 分钟左右,回来尝试在网站上做任何事情时,登录窗口会重新出现。这个解决方案在我们的服务器上运行了一段时间 - 现在它又回来了。我的本地开发盒在 VS2008 中运行 Cassini 时不会出现此问题。
关于如何解决这个问题的任何想法?
【问题讨论】:
标签: asp.net session-timeout httpcookie