Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy Doesn't Asp.Net Session.Clear() Work On Close Tab When I See It Run?
    primarykey
    data
    text
    <p>I have been attempting to get a clean break from a session when a tab is closed for a workplace system used by supervisors and others. I am successful when the person logs out - all is cleared. However, when a tab is closed, it can be reopened at will as if session.clear() was never called.</p> <p>I am using this javascript:</p> <pre><code> $.ajax({ type: "POST", url: "default.aspx/EndSession", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { } }); </code></pre> <p>to call this web method:</p> <pre><code>[WebMethod] public static string EndSession() { HttpContext.Current.Session.Clear(); HttpContext.Current.Session.Abandon(); HttpContext.Current.User = null; FormsAuthentication.SignOut(); return ""; } </code></pre> <p>I set a breakpoint and watch the code execute as I step through it and it returns. The tab closes, and then I right-click and select "reopen closed tab" and the page comes back and the session is still active.</p> <p>I see <a href="https://stackoverflow.com/questions/1921941/close-kill-the-session-when-the-browser-or-tab-is-closed">here</a> ppl saying this is not possible, but don't understand why, since the code is running on the server - I'm watching it run, and the session is not cleared. I would have thought this was the point of an explicit call to "Session.Clear()" and "Session.Abandon()". The same code in the logout Page_Load works great.</p> <p>Why? What am I missing? Is the session clear being thrown out after running because the tab is closed?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload