我有一个使用 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 文件的 auth 部分如下所示:
<authentication mode="Forms">
<forms name="APLOnlineCompliance" loginUrl="~/Login.aspx" defaultUrl="~/Course/CourseViewer.aspx" />
</authentication>
当我登录该站点时,我确实看到cookie 被正确发送到浏览器并传回:
HttpFox 输出 http://cid-e79f8e4b07c3e30f.office.live.com/embedphoto.aspx/Public/SessionProblem.png
然而,当我离开 20 分钟左右,回来尝试在网站上做任何事情时,登录窗口再次出现。这个解决方案在我们的服务器上运行了一段时间 - 现在它又回来了。在 VS2008 中运行 Cassini 的本地开发盒上不会出现此问题。
有想法该怎么解决这个吗?