2012-10-17 80 views
1

可能重複:
How to Check whether Session is Expired or not in asp.net檢查會話超時ASP .NET

什麼是檢測頁面,如果一個會話中的代碼超時背後的最好方法? 我在博客中找到了下面的代碼(http://mattslay.com/detecting-session-timeout-in-asp-net/)。沒關係,還是有更好的方法?

if (Context.Session != null && Context.Session.IsNewSession) 
{ 
    string cookieHeader = Page.Request.Headers["Cookie"]; 
    if ((null != cookieHeader) && (cookieHeader.IndexOf("ASP.NET_SessionId") >= 0)) 
      return true; // timeout occured 
    else 
      return false; 
} 

回答