Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I run code immediately before session end? 1

Status
Not open for further replies.

tcstom

Programmer
Aug 22, 2003
235
GB
I want to run some code immediately before a user session ends. I'm holding a user object in that session and when the session times out or is abandoned I want to pick up that user object and use it to clear out locks in the database before it is destroyed from the session. I've tried doing this in the global Session_End method but preliminary tests suggest that this is fired AFTER the session is ended. Is there any way to fire a similar method JUST BEFORE the session ends?
 
Web applications are stateless and they only respond to requests, so it's not a good idea to expect the server to do something without receiving a request. I'd rethink your approach with regards to why you need the locking, or look at another method for cleaning up the locks.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
I would have thought the end of a session timeout could be considered as much of a request as the beginning of a session timeout. I had presumed some sort of event was fired to invoke the termination of a session so I was hoping I could handle it. Anyway, if can't be done perhaps I'll have to use the IP address to identify locks. It's running on an intranet so should be OK.
 
I would have thought the end of a session timeout could be considered as much of a request as the beginning of a session timeout.
Why? Say for example, I start a session by navigating to my web page and therefore creating a request. Then, after one minute I close my browser, turn off my computer and walk away; the server has no way of knowing that I have done this. The session end event will still fire when the session times out (the default is 20 minutes) but I haven't made any request.

I had presumed some sort of event was fired to invoke the termination of a session so I was hoping I could handle it.
Yes, an event is fired (Session End) but it's just because the session has timed out. The session details no longer exist so you can't "clean up" after yourself.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top