Last post Feb 09, 2017 05:57 PM by nathon
Mar 26, 2009 12:18 PM|Sigray|LINK
Is it possible to get a reference to the current ApplicationInstance (HttpApplication Class object) directly from a custom class or dll? I know you can get the current HttpContext with HttpContext.Current, but what if your method is being called from outside
of a HTTPContext scope.
For example, if your method is being called from Session_End, there is no HttpContext, but my method needs to be able to directly access the current ApplicationInstance.
Mar 26, 2009 04:58 PM|roimer|LINK
If you are managing the Session_end event from global.asax you can get a reference to the Current application instance with:
But, if I understand, you are programming a Class (in a DLL) that needs access to the HttpApplication Object, I'm right? Well, I programmed a couple of classes in a DLL that needed access to the session object, I thing that the way of access is the same.
You may get it using: System.Web.HttpContext.Current.ApplicationInstance. Of course, you need first to make a reference to the System.web library from your DLL project.
Mar 26, 2009 05:50 PM|Sigray|LINK
You correctly identified my problem. However, System.Web.HttpContext.Current is null during Session_End, because the event is being fired when a session is ending and not in response to a http request. I need to know if there is a way for an external method
to find the current HttpApplication without it being specifically passed to the method.
Feb 09, 2017 05:57 PM|nathon|LINK
I know this post is old. However, I just ran through how to get session information inside of an HttpModule so I thought I'd do a write up and leave a reply, in hopes it would help others. Here's the post on my blog.