Session_End, where is my Request?
This is one of the most common misunderstandings about ASP.NET -- so common that I even blundered it myself in a newsgroup post, even though I know better. A typical question might go like this:
"I have code in my session_start to create a temp directory for the session. On session_end it is supposed to delete the directory but doesn't seem to be firing. I've enclosed the code below. Can anybody give me any suggestions as to why Session_End seems to not be being fired?"
<sample code from the OP>
Session_End only fires for InProc Session mode, and it fires on the server. It is completely independent of any "Request" -- in fact that's the reason it fires - because there *IS* no Request and there hasn't been one for some time!
So -- the concept of getting anything out of a Request when Session_End fires is a moot issue.
At least you can access session variables in Session_End!
ReplyDeleteThat's right, you do have access to the session that is currently expiring in the Session_End handler. But, if you have some cleanup or other business logic to do, you would first have had to store the SessionID associated with that particular user somewhere, such as in a database. Then, you could look up that user's table row by "CurrentSessionID" and update their data.
ReplyDeleteI have an AJAX based application which is periodically posting on an ASPX page & still after some random interval my session_end hits. Any ideas what the issue could be?
ReplyDelete