how to catch session end when press title bar close button asp.net c#

615 Views Asked by At

I have some question about asp.net web application. Web application which use sql server session state. Logout event can session remove but press title bar close button want to remove session. Which events can control when press title bar close button. I read about session_end event can catch when press title bar close button. But can't arise session_end event using sql server session state. How can to catch?

1

There are 1 best solutions below

0
On

Closing the browser does not end the session on the server, the server can't tell the difference between an open or closed browser, it simply receives a request and then sends a response and sits there waiting for another request. After a certain amount of time with no requests the session will time out and the session_end event will run.

If you wanted to end the session would have to have some kind of ajax request post back to the server when you closed the browser in order for the server to know to end the session.

EDIT

you could do something like this using jQuery

$(window).unload(function() {
  $.post('someurl');
});

replace someurl with the url of a web service, handler or mvc controller action or similar that tells the server that the browser has been closed.

Then server side you just do

Session.Abandon();