This seems to work:
Session.Abandon(); Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));
By clearing this cookie, a new session will be created on the server with a new session identifier.
(Link: Microsoft Support )
EDIT: Here's an example of using AJAX (with jQuery) to invoke server code without refreshing the page - it calls twice, once to delete the first session, and once to create a new one. Maybe the best way, but it works.
function newSession() { jQuery.ajax({ type: "POST", url: "WebForm1.aspx/ClearSession", data: "{}", dataType: "json", contentType: "application/json; charset=utf-8", success: function () { jQuery.ajax({ type: "POST", url: "WebForm1.aspx/NewSession", data: "{}", dataType: "json", contentType: "application/json; charset=utf-8", success: function () { console.log("Success!"); }, error: function (x, y, z) { console.log("Failure!"); } }); }, error: function (x, y, z) { console.log("Failure!"); } }); }
And by code (for WebForms - you can also do this using the MVC controller):
[WebMethod] public static void ClearSession() { HttpContext.Current.Session.Abandon(); HttpContext.Current.Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", "")); } [WebMethod] public static void NewSession() { HttpContext.Current.Session["x"] = 123; }
source share