title: MVC 4 Detecting Session Timeout
body: <p>Unable to get the following standard code to work.  Looking for a complete sample project or help on how to bug. 
  The following code...</p>
  
  <pre><code>public override void OnActionExecuting(ActionExecutingContext filterContext)
  {
      if (filterContext.HttpContext.Session != null)
      {
          if (filterContext.HttpContext.Session.IsNewSession)
          {
              string cookie = filterContext.HttpContext.Request.Headers["Cookie"];
              if ((cookie != null) &amp;&amp; (cookie.IndexOf("_sessionId") &gt;= 0))
              {
                  filterContext.Result = newRedirectResult("~/SessionExpired/Index");  //redirect anywhere to message user UI , never hits this breakpoint
                  return;
              }
          }
      }
      base.OnActionExecuting(filterContext);
  </code></pre>
  
  <p>}</p>
  
  <p>is standard for checking session expiration.
  However in my case the the line <code>(cookie != null) &amp;&amp; (cookie.IndexOf("_sessionId") &gt;= 0)</code>
  <strong>always returns false</strong> and thus the user is never redirected.</p>
  
  <p>I am testing with a brand new wizard created MVC 4 project.
  I cannot find a complete download sample.  I suspect my config my be wrong.</p>
  
  <pre><code>&lt;authentication mode="Forms"&gt;
      &lt;forms loginUrl="~/Account/Login" timeout="1" slidingExpiration="true" name=".ASPXFORMSAUTH" /&gt;  
  &lt;/authentication&gt;    
  &lt;sessionState mode="InProc" timeout="1" cookieless="false"/&gt;
  </code></pre>
  
  <p>Please advise why this code fails or provide a link with a complete download sample project.
  .Net 4.5 | VS 2012 | local IIS Web Server , IIS Express</p>
  
  <p>re: <a href="https://stackoverflow.com/questions/1490879/detecting-session-expiry-on-asp-net-mvc">Detecting Session expiry on ASP.NET MVC</a></p>