tags:

views:

359

answers:

2

Why session_end event is not getting called when we close a browser ?

+7  A: 

Because the session doesn't end when the browser is closed. The session ends when it's timed out, or it is explicitly ended, server-side.

The browser closing really has nothing to do with the connection to the server. The connection is already over, once the page is fully loaded (excluding some funky ajax).

Noon Silk
But when you close the browser and on closing if it clears the cookies then Session will automatically get closed.
rahul
The cookies are used to correlate the request from the browser to stored session state on the server, so having the cookie cleared only means that future requests won't be correlated. It still does not mean that the stored session state on the server is cleared (before the session times out).
jwanagel
A: 

Silky has right, but you can try call ajax oneway method binded to onbeforeunload event and on server you can handle this event. But it'll be probably not very reliable and works not in all browsers.

<body onbeforeunload="ClosingWindowAjaxEventHandler();">
Jan Remunda