我有一個使用Forms Auth的站點。客戶端不希望網站會話對用戶完全失效。在登錄頁面代碼隱藏,下面的代碼被用於:ASP.NET Webforms使用HTTPCookie的站點在20分鐘後超時100年
// 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>
當我登錄到該網站我see餅乾是正確的發送到瀏覽器,並通過備份:
HttpFox output http://cid-e79f8e4b07c3e30f.office.live.com/embedphoto.aspx/Public/SessionProblem.png
然而,當我走開了20分鐘左右,再回來重要在網站上做任何事情,登錄窗口會重新出現。這個解決方案在我們的服務器上工作了一段時間 - 現在又回來了。在VS2008中運行Cassini的本地開發框中不會出現這個問題。
有關如何解決此問題的任何想法?
看起來不錯。我的意思是有兩個單獨的超時時間 - 一個用於您的身份驗證票證,該票證設置爲100年。但是會話超時也是如此,默認情況下會設置爲20分鐘,所以對我而言這聽起來像是影響了一些東西。常見模式是將Session_End事件掛接到Global.asax中的處理程序,該會話將在用戶會話過期時將用戶從Formsauth工單中註銷。 – womp 2010-06-11 20:35:21
對 - 我沒有那種類型的東西。有沒有辦法強制會話超時到無或無限,所以它默認爲HTTPCookie? – Rob 2010-06-11 20:39:44
可以在web.config中設置會話超時:http://msdn.microsoft.com/en-us/library/h6bb9cz9.aspx。然而,它不能設置長於1年。 –
womp
2010-06-11 20:55:56