Abandon session during request
<p>I have such a requirement for my ASP.NET MVC app:</p>

<blockquote>
  <p>Session created before authentication should be closed and new session, with new ID, should be started</p>
</blockquote>

<p>So it should work like this:</p>

<ol>
<li>User is redirected (GET request) to my app (some method in the controller) with auth info </li>
<li>Closing old session, starting new one</li>
<li>Auth, saving user data to the session</li>
</ol>

<p>Let's look to the controller:</p>

<pre><code>public ActionResult Login(string token) {
    Session.Abandon(); // I want new session!

    // Some auth stuff

    Session["this"] = "x";
    Session["that"] = "y";

    return View();
}
</code></pre>

<p>On debugging, i can see session values "this" and "that" set to "x" and "y". But now let's go the view that this method uses:</p>

<pre><code>@{
    var @this = Session["this"]; // Wut? @this is null
    var that = Session["that"]; // Wut? that is null
}
</code></pre>

<p>So, a little digging gave me the answer:</p>

<blockquote>
  <p>Abandon causes the End event to be raised. A new Start event will be raised on the next request.
  <a href="https://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.abandon%28v=vs.110%29.aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.abandon%28v=vs.110%29.aspx</a></p>
</blockquote>

<p>It seems that lifecycle looks like this:</p>

<ol>
<li>"Session.Abandon()" - session marked to be closed</li>
<li>Setting session values.</li>
<li>"return View()"</li>
<li>Session closed and (not sure about this) new session started</li>
<li>View - session values set in controller are missing.</li>
</ol>

<p>Completly unacceptable. How can I overcome this?</p>