HttpContext.Current is nothing in Global.Asax Session_End? Any workarounds?

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
NixDev
10/24/2008 2:40:15 PM
asp.net.web-forms 93655 articles. 3 followers. Follow

3 Replies
4418 Views

Similar Articles

[PageSpeed] 52

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
stealth_pt
10/24/2008 3:02:20 PM

e (System.EventArgs) comes "empty" :(

0
NixDev
10/24/2008 5:18:04 PM

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
Hua
10/29/2008 3:27:54 AM
Reply:

Web resources about - HttpContext.Current is nothing in Global.Asax Session_End? Any workarounds? - asp.net.web-forms

CONTENTS "LAN Technical Reference: 802.2 and NetBIOS APIs" IBM Library Server
Summarize COVER Book Cover NOTICES Notices EDITION Edition Notice CONTENTS Table of Contents FIGURES Figures TABLES Tables FRONT_1 Notices FRONT_1.1 ...

Feature Extraction with Redis
So fresh and (not) so clean One great thing about applying machine learning at Preact is working with fresh data. In the world of academic research, ...

Resources last updated: 3/9/2016 4:00:22 AM