title: Check for session timeout asp .net
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/10480110/how-to-check-whether-session-is-expired-or-not-in-asp-net">How to Check whether Session is Expired or not in asp.net</a>  </p>
  </blockquote>
  
  
  
  <p>What is the best way for a page to detect if a session has timed out in the code behind?
  I found the below code in a blog (<a href="http://mattslay.com/detecting-session-timeout-in-asp-net/" rel="nofollow noreferrer">http://mattslay.com/detecting-session-timeout-in-asp-net/</a>). Is is ok or is there a better way?</p>
  
  <pre><code>if (Context.Session != null &amp;&amp; Context.Session.IsNewSession)
  {
       string cookieHeader = Page.Request.Headers["Cookie"];
       if ((null != cookieHeader) &amp;&amp; (cookieHeader.IndexOf("ASP.NET_SessionId") &gt;= 0))
            return true; // timeout occured
       else
            return false;
  }
  </code></pre>