In an ASP.NET MVC 5 app, I'd like to reset the session ID when the app starts. Using this answer should reset the session ID. I've applied that code in Global.asax.cs
:
protected void Session_Start(object sender, EventArgs e)
{
Session.Abandon();
Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));
var manager = new SessionIDManager();
string newID = manager.CreateSessionID(Context);
bool redirected = false;
bool isAdded = false;
manager.SaveSessionID(Context, newID, out redirected, out isAdded);
}
However, with the above code, the session ID remains the same between Session.Abandon()
and after manager.SaveSessionID()
(I use the Immediate Window in Visual Studio and test by running this: Session.SessionID
).
Am I doing this in the right point in the app lifecycle? What am I doing wrong?