9/06/2007

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.