Translate

Friday, June 6, 2014

onbeforeunload remove session data

$(window).bind('beforeunload', function(){ 
     var path = $(location).attr('pathname') + "/RemoveSessionData"; 
     $.ajax({ type: "POST", url: path, async: false });
}); 

[System.Web.Services.WebMethod(EnableSession = true),  System.Web.Script.Services.ScriptMethod(UseHttpGet=false)]
public static void RemoveSessionData()
{
       HttpContext.Current.Session.Remove(SessionMember1);
       HttpContext.Current.Session.Remove(SessionMember2);
}