title: Why am I getting a new session when using async actions and RedirectToAction in ASP.NET MVC?
body: <p>I have an ASP.NET MVC 4 application that is exhibiting session management problems.</p>
  
  <p>I'm using the Session to track the logged in user. I have a custom action filter that checks a user is logged in and, if not, redirects to the log in page.</p>
  
  <p>This <em>generally</em> works fine. However, I have a problem where a new session is getting created during a certain request. The session ID is the same, but the Session.IsNewSession property shows it's a new session - and the session contents have gone.</p>
  
  <p>The action where is happens is an async action (using the async/await features in .NET 4.5). I <em>don't</em> manipulate the session in the thread that is invoked with the await keyword. When the await operation completes, I then do a RedirectToAction to display the results of the operation.</p>
  
  <p>When I check the session, just before executing the action I've redirected it to - it has the custom access attribute on it - that's when I find a new session has been created (so the authentication fails and I'm return to the login page).</p>
  
  <p>I use RedirectToAction at numerous points in the application, so that can't be the issue (or at least the <em>only</em> issue). Could the problem be something to do with the async/await call - even though I don't use or need the session within the code that is invoked by the await? </p>
  
  <p>Is returning the ASP.NET thread to the pool and getting it back invalidating the session? If so, what's the solution? Can I save and restore the session across the await? Or will I have to implement some custom logic that records that the user was logged in in my database, for example?</p>