i need to sign out an authenticated user in ASP.NET reliably when a browser tab gets closed. What is the recommended solution?
Thanks
i need to sign out an authenticated user in ASP.NET reliably when a browser tab gets closed. What is the recommended solution?
Thanks
Typically you would do your sign-out logic when the session has ended. But if you had to detect when page is closed, use this:
<body onunload="performMyLogoutLogic();">
...
...
</body>
You could use a generic handler to kill session and call this beforeunload like this:
function CloseSession( )
{
location.href = 'KillSession.ashx?task=1';
}
window.onbeforeunload = CloseSession;
And in your KillSession.ashx do this
public void ProcessRequest(HttpContext context)
{
if(!String.IsNullOrWhiteSpace(Request.QueryString["task"].toString()))
{
if(Request.QueryString["task"].toString()=="1")
{
Session["User"]==null;
context.Response.ContentType = "text/plain";
context.Response.Write("Good Bye!");
}
}
}