views:

285

answers:

2

Hi,

When i close the browser window from the task bar the session is not getting destroyed. I could handle this on closing the browser using close(X) button or by pressing Alt+F4 using javascript. But from the task bar if i close the window how can i clear the session? The problem occurs only when there is another browser window already opened before closing the current window. When i go access the application it will directly go to the page previously accessed as the session is still valid.

Any help appreciated.

Thanks in advance,

Nikesh P

+1  A: 

You can't - the session is on the server side and the browser does not inform the server when it is terminated.

The usual way is to set a timeout for the session,m so if the browser hadn't accessed the server for X minutes the session closes.

David Rabinowitz
I'v seen cases where the session timeout was set very low, on the order of one minute, with the browser sending a regular ajax "ping" to the server to keep the session open. Can be useful in cases where you need to know when the browser is shut, and you need to know relatively quickly.
skaffman
thanks david,but the thing is that the session timeout for the application should be 30 minutes which is already set. :(
Nikesh P
A: 

Maybe you can use client-side session cookie to complement your server-side session management mechanism, maybe to store 'session id' and have it checked against the server side sessions. The cookie will be destroyed when the browser exits, so the second window won't be able to continue the session now that the 'session id' is gone.

Lukman