Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more: , +
How to session expire when browser autmatically shut down in asp.net..
Posted

Use beforeunload | onbeforeunload event.
Read here[^]
 
Share this answer
 
 
Share this answer
 
Setting a timeout is the best approach.
Since a browser can vary, it will be difficult to capture the close event.
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 2-Jul-14 3:02am    
Timeout will shut session on ... time-out, not on browser close...
SRS(The Coder) 3-Jul-14 1:28am    
Yes, Kornfeld Eliyahu Peter is right...

The main issue will be, even if user closes the browser the session will be out after the time expired only not immediately on browser close.
For example let say session timeout is set to 10 mins. Now you logged into an application and closed the browser still the session will be there for 10 mins, within which if you again try to open the application same page you will be able to view it. So we need to expire the session on the browser close event itself.

There are two ways to do it like 'onbeforeclose' of current window or 'onunload' of the body.

Just wondering which one and why should be better among these two :-(
There is no way to handle browser automatically shutdown just you need to set a session time to be maintained and after which the session will end automatically.

If you want closing browser can be handled, event name is 'onbeforeunload' which might be of help to you. See the below link :-

http://forums.asp.net/t/1969069.aspx?Call+c+method+inside+onbeforeunload+event+JS[^]


Hope this will give you an idea to proceed further.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900