Hi all.
I'm trying to implement a realtime monitoring system for a web site, pretty much a copy of the one published here:
http://microsoft.apress.com/asptodayarchive/72060/actively-monitoring-your-aspnet-web-site-users
Now, I have a hashtable whose key is SessionId. It is used to store session-specific information. So, when the session ends (be it because the user clicks the "logout" button which calls Session.Abandon, or due to a timeout) I want to remove that info from my Hashtable (otherwise as days pass, I'll end up with a hashtable full of stale data).
The problem I'm having (and it seems its a fairly common one, due to the amount of related questions i found on several forums) is that on Session_End event in Global.Asax, HttpContext.Current is nothing (let alone HttpContext.Current.Session.SessionId).
I wonder if the original code by Andrew Krowczyk has been tested in real apps, because I can't for the life of me imagine what I'm doing wrong. Even more, since Session_End can be fired because of a Session timeout, in that case it seems natural that HttpContext is nothing...After all, there's no HTTP request associated to it. But even in the "simpler" and normal scenario, where a user clicks "logout" and I programatically call Session.Abandon HttpContext.Current happens to be nothing....
Any ideas?
![]() |
0 |
![]() |
Hi,
have you tried to see wath type of object is the sender in the Session_OnEnd? Maybe it is a session object. I don't know but I think you should give it a try!
Wish you luck
![]() |
0 |
![]() |
e (System.EventArgs) comes "empty" :(
![]() |
0 |
![]() |
Hi NixDev,
In fact, 'HttpContext.Current' is nothing on Session_End event in Global.Asax.
But you can use 'Session.SessionID' to get the SessionID.
public void Session_OnEnd(Object sender, EventArgs e)
{
Session.Clear();
Hashtable tempHash = (Hashtable)Application["SessionList"];
tempHash.Remove(Session.SessionID);//right
tempHash.Remove(HttpContext.Current.Session.SessionID);//error
}I guess that the 'HttpContext.Current' is destroyed on the event Session_OnEnd, but Session object still exist.
Sincerely,
Hua Jun Li
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
![]() |
0 |
![]() |