这是我先前的做法.
            bool isNewSession = HttpContext.Current.Session.IsNewSession;
            
string logoutUrl = root + "home/logout";
            
if (isNewSession)
            {
                     
// if (HttpContext.Current.Session["sessionID"] == null) 这方法土了些,要创建一session变量.
                     JScript.AlertAndRedirect("登录已超时,请重新登录!", logoutUrl);      
            }

可是不准确,搞不懂的是,我没有新开窗口,session没有过期的情况 isNewSession有时还会是True.
以下是参照:
http://blogs.msdn.com/psundars/archive/2007/11/07/how-do-i-detect-a-session-has-expired-and-redirect-it-to-another-page.aspx
后的代码:

bool isNewSession = HttpContext.Current.Session.IsNewSession;
            
string logoutUrl = root + "home/logout";
            
if (isNewSession)
            {
                 
string strCookieHeader =HttpContext.Current.Request.Headers["Cookie"];

                 
if (null != strCookieHeader && strCookieHeader.IndexOf("ASP.NET_SessionId">= 0)
                 {
                     JScript.AlertAndRedirect(
"登录已超时,请重新登录!", logoutUrl);
                 }
            }



-----------------------------------------------------
关于session和cookie的关系
Session是可以依赖Cookie的,意思就是您也可以不使用Cookie来保存SessionID, 关于如何在无Cookie 会话状态下Session的使用您可以参考MSDN:http://msdn.microsoft.com/zh-cn/library/system.web.sessionstate.httpsessionstate.sessionid(VS.80).aspx.

当使用Cookie来保存这个SessionID时,之所以找不到相应的Cookie,是因为它是保存在内存当中的。

相关文章:

  • 2021-07-19
  • 2021-10-16
  • 2021-07-30
  • 2022-12-23
  • 2021-12-26
  • 2021-11-30
  • 2022-12-23
  • 2021-07-23
猜你喜欢
  • 2022-12-23
  • 2021-07-01
  • 2021-12-06
  • 2022-12-23
  • 2022-02-04
  • 2022-12-23
相关资源
相似解决方案