title: Detecting Session expiry on ASP.NET MVC
body: <p>I have built a shopping cart that uses Session State to keep the shopping cart data while the user is browsing the store.</p>
  
  <p>I have an issue where if I leave the browser window open for a long time on step1 of the shopping cart, then press "go to step 2", my actions throw an error because the step2 action assumes the session hasn't expired and the ShopCart object is in the correct state.</p>
  
  <p>I would like this scenario to be nicer for my users, but I think i need to somehow detect if the session has expired so that on next request I can throw them to Step1.</p>
  
  <p>I found the following code that claims to to solve the problem, but it doesn't work for me.</p>
  
  <p>The IsNewSession condition is true but the condition</p>
  
  <pre><code>if ((null != sessionCookie) &amp;&amp; (sessionCookie.IndexOf("ASP.NET_SessionId") &gt;= 0)) {
     // handle expired session
  }
  </code></pre>
  
  <p>always returns false and it never handles the invalid session. I'm confused.</p>
  
  <p>Is this possible in ASP.NET (and MVC)?</p>