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);
- }
- }
- }
- }
本文介绍了一种在Session超时后使FormsAuthentication登出的方法,通过在Global.asax中添加特定代码实现。此方法可避免Session超时后IsAuthenticated仍为真导致的问题,但可能会影响Ajax请求。
4968

被折叠的 条评论
为什么被折叠?



