Session超时后,FormsAuthentication的IsAuthenticated仍然为真,如果此时未加考虑使用Session中的值,就会有问题。google了好长时间,下面代码是在Global.asax中添加,让Session超时时FormsAuthentication登出。
- protected void Application_AcquireRequestState(object sender, System.EventArgs e)
- {
- if (Session != null && Session.IsNewSession)
- {
- string szCookieHeader = Request.Headers["Cookie"];
- if ((szCookieHeader != null) && (szCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
- {
- if (User.Identity.IsAuthenticated)
- {
- FormsAuthentication.SignOut();
- Response.Redirect(Request.RawUrl);
- }
- }
- }
- }