I want to clear the session on Page unload.
Here is a condition :
- If user goes from Page A to Page B of the same site session must not get cleared.
- If user close the browser window or Tab(close the site),session must gets cleared.
I have tried using AJAX PageMethod to call server-side procedure to remove session from client side script.But the procedure is not getting hit,I have checked it using Breakpoint.
server side procedure is in master.cs file
I will appreciate your help.
Here is code in site.master
<body onunload="HandleClose();">
<script type="text/javascript">
function HandleClose()
{
PageMethods.AbandonSessions();
}
and here is a code in master.cs :
[System.Web.Services.WebMethod]
public static void AbandonSessions()
{
HttpContext.Current.Session.Abandon();
}