Session_End

  • Thread starter Thread starter Imran
  • Start date Start date
I

Imran

Hi..,

I tried to execute some code in the Sub Session_End in
the Global.asax, but its not working.
I am developing the asp.net application on Windows Server
2003 and IIS6. Tell me whats the problem.

Imran
 
How do you know it's not working? Session_End will fire at the end of a User
Session, but it may not be firing when you expect it to. Sessions usually
end by timing out from lack of Requests, and the default time-out period for
Sessions is, I believe, 20 minutes. In addition, if you're debugging, of
course the Session_End will not fire if you stop debugging.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
I tried to execute some code in the Sub Session_End in
the Global.asax, but its not working.


Depends on what you mean by "not working". If you have out-of process
session state, you won't receive Session_End.
 
Alvin Bruney said:
see this article for a full discussion on session_end event
http://tinyurl.com/2t7gq

I came across a couple of these articles all saying the same thing. It
sounds very credible but when I try it, it just appears it doesn't work that
way. Maybe something broke since version 1.1 of the .NET Framework or it is
not the whole story. I am using mode=InProc, I do put the current date in a
session variable from the Page_Load event, I post back the form by clicking
a button and execute HttpContext.Current.Session.Abandon(). No Session_End
event.

I tested the code I put in Session_End separately before pasting it in
(since it is supposed to fail silently on errors when the session expires).
It just doesn't fire, Session_End is one big lie in ASP.NET.

Martin.
 
post a complete working example demonstrating the problem. I will take a
look at it.
 
Alvin,
post a complete working example demonstrating the problem.
I will take a look at it.

That is very nice. However, I've been at it all day and I found what the
problem was.

After making a small project in Visual Studio I found that to work just
fine. Then it was a matter of finding the differences between my hand-made
project and the little thing that Visual Studio spit up. And there were a
lot of differences...

I finally discovered that my test code that was called from several
application events to help me see the sequence of events failed silently. It
messed with the User object and although I was being a good boy doing

if (User == null) ...

before accessing any members, this still was the code that broke it all.
User is not available at all times (since it is really
HttpContext.Current.User). After I started checking for null with
HttpContext.Current it was okay.

So these silent errors in one or more application events prevented ASP.NET
from finishing some sequence and setting some hooks, causing Session_End not
to be fired later on.


Now had I started doing my project from within Visual Studio from the start
I might have hit the error straight away in the debugger (or maybe not, I
don't know how and if the debugger hooks up with application events). It
doesn't seem too hard to wrap a Visual Studio project around my site, I will
probably do so soon now that I felt how much time I can spend finding
something silly as this.

Thanks for the insights. I did learn a lot in the process. I still feel
stupid though, now why would that be :-).

Martin.
 
phew!!!, that was a nasty one. thanks for keeping us informed. i'm sure it
will help somebody else later.
 
Back
Top