Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How session get expires when user close browser? Also, as soon aa I close the window am not hitting the Application_End event in my code base. Can you please let me know what could be the problem
Posted
Updated 25-Jun-12 5:11am
v2

Nothing. Session will not expire when uses closes the browser. As http is stateless, the server is not seeing what happens on client side. Session expires when is set to expire (see here[^]), regardless of client browser.
The application_end event primarily fires when the IIS pool is recycled or the application itself is unloaded. One other thing to note, that a change to a dependent file (say web.config) will cause the application to reload itself, which will in cause the application_end event to fire while it is closing itself off.
If you need to handle session end, you can follow this article: ASP.NET HttpModule for handling session end with StateServer[^]
 
Share this answer
 
v2
Comments
Ravindranath.net 25-Jun-12 11:30am    
We use windows authentication in our applcation, we aren't handling the session_end event when user closes the browser. My applcation is a letter generation app, we are running the endurance test for 8 hours, we are closing the browser after creating each letter and opening the new ie window for creating new letters,My Question is, if session didn't get expire as soon as we close the browser, how abt the objects are they get unreferenced as soon as we close the window?
Dave Kreskowiak 25-Jun-12 14:01pm    
They don't! The session will eventually expire (timeout) on it's own. You may have to wait about 20 minutes (default I think) for that to happen, but it will eventually happen.

You don't have to close to browser to start this countdown. You just have to do nothing at all. Just leave the browser window alone or close it, but in either case you just wait.
Zoltán Zörgő 25-Jun-12 15:43pm    
Dave Kreskowiak's answer is correct. Please note, that web applications are really different from windows forms applications. The "life" of an application is passed from browser to server and back. The browser formulates a request, sends it to the server. The server processes it and sends the html code or other content back to the client and goes to sleep. It does not have any connection to the client. It will wake up when the user/browser has an other request. The session id kind of state link between the different requests. Id does not matter if the user closes the browser, kills it, or the connection is lost for a long time, the session will expire if the time goes out. The timer is reset only if the client is using the session-id again before it times out. Because of this, you can not rely on the client. You need to use this timeout. Since an application is used by many users, the session_end is the first point to catch the end of a user session. The application itself is living an other life: is starting at the first load (even without user request), and will end if id is not called for a long time.
 
Share this answer
 
How session get expires when user close browser?
Session expires by itself based on timeout.

as soon aa I close the window am not hitting the Application_End event in my code base
Browser close fails to raise the event method as the browser gets closed by the time it can be raised.

Can you please let me know what could be the problem
It's a known issue and you can try to handle the page unload event in your Javascript. But, passing it to server in time might be a problem.
 
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