aspx:
<%@ Page Language='C#' AutoEventWireup='true' CodeFile='Default.aspx.cs' Inherits='_Default' %>
function HandleClose() {
alert("Killing the session on the server!!");
PageMethods.AbandonSession();
}
codebehind:
[WebMethod]
public static void AbandonSession()
{
HttpContext.Current.Session.Abandon();
string strh = "sp_IsHistory";
SqlParameter param5 = new SqlParameter("@senderid", 1);
SqlParameter param6 = new SqlParameter("@receiverid", 5);
SqlHelper.ExecuteNonQuery(CommonSetting.GetConnectionString(true), CommandType.StoredProcedure, strh, param5, param6);
}
Abhishek JainPosted Aug 14, 2013, 6:07 AM
As i have mentioned in my last post that you can make AJAX request but that is not possible in all the browsers
Every browser behaves differently, Like you can make an AJAX request to the server(either HTTPHandler or Service and not the WebMethod on the same page) from Internet Explorer from unload event but this will not work in Google chrome. I tried to make an AJAX request to an HTTP handler from unload event on Internet Explorer and it is working fine.
For Making AJAX Request i have used this code(AJAX request using jQuery).
If you don't know hot to create HTTP handler you can refer a section(For Creating HTTP Handler) in one of my post http://www.c-sharpcorner.com/UploadFile/25c78a/jquery-ui-autocomplete/
I haven't checked but it will definitely behave differently in Safari and Firefox.
this is not a full proof solution as it is browser dependent and you can't change the browser behaviour.
yadagiri uppariPosted Aug 14, 2013, 12:47 AM
is it possible to run code behind method when browser is closed(x mark)?...if possible
share with code sir...please try to solve...i am facing this issue from a week
Abhishek JainPosted Aug 13, 2013, 9:22 AM
you can make an AJAX request but i am sure that you will never get the response from that request, because till the time you can get the response the page on the client side is actually disposed.