Session_End doesn't call after i close browser

1.7k Views Asked by At

I use below setting in web.config

<sessionState mode="InProc" cookieless="false" timeout="10"/>

...

<authentication mode="Forms">
<forms loginUrl="login.aspx" timeout="10"/>

and in Session_End according to Session's value i change a column's value in database (if this column's value is 1 means user online) but sometimes after a day that user close browser this column's value steel is 1 (means Session_End doesn't call after user close browser)

2

There are 2 best solutions below

2
On BEST ANSWER

No Session_End will not call on page close. You need to use script for that

<script>    
window.onbeforeunload = function (evt) {
var message = ‘Are you sure you want to leave?’;
if (typeof evt == ‘undefined’) {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
}
return message;
}

</script>

Using this script you can identify when user closes the browser

0
On

No event will be called if your browser is closed, it will be called after timeout.

The event should be called, but not necessarily right after the timeout.

You could try from a Browser: Start a session,wait > 1 minute, do a Postback somehow

This should help to verify that the Timeout works and I think you will also see the SessionEnd happening at that time. Otherwise, just wait and start some other sessions. The system will come around o calling it sometime.

http://forums.asp.net/t/1689960.aspx/1