What is intersting is that in your original post you said that you can log ok when debugging, but in production web site the variables are not logged.
This is the root cause of your issue as you SHOULD be able to capture that data.
I'm sure you know some of this already, but I'll explain anyway(!):
In the Application_Error event, the sender object can be cast and you can retrieve the HttpApplication object and the HttpContext:
The HttpContext is the class that corresponds to the current HttpRequest in process. It is always available during the page lifecycle.
In fact there is a static method on the class:
HttpContext.Current
that retreives the current context, so you can in fact utilise it anywhere.. it doesn't have to be passed in as a method parameter.
When your code is executing in your page/business/data layers at the HttpHandler level, when an exception is encountered the HttpContext object is still current and instantiated.
Therefore the object's properties will still be valid... Request, Response, Session etc.
So it is very strange that these objects do not produce any data when an error happens at this stage of the request life cycle.
(To read more on the application life cycle, here is a great article from MSDN ASP.NET Life cycle overview )
You therefore, in my opinon, have a particular production issue where the data is not being catpured..
either there is something wrong in the lifce cycle OR your code for capturing is somehow not working due to different settings between dev and live set ups.
Contact me by email via my profile here on the site and I can send you my email address if you wish - if you share the portion of code that is actually processing inside the Application_Error event I might be able to advise if there is a specific code issue.
Otherwise, I am not really a production debugging expert, so cannot advise further on getting to the source of your problem.
What I can tell you is the information SHOULD be available to you.
foreachbiscu...
Participant
1598 Points
210 Posts
Re: Access Session Variables from Application_Error event in Global.asax
Oct 31, 2007 09:40 AM|LINK
What is intersting is that in your original post you said that you can log ok when debugging, but in production web site the variables are not logged.
This is the root cause of your issue as you SHOULD be able to capture that data.
I'm sure you know some of this already, but I'll explain anyway(!):
In the Application_Error event, the sender object can be cast and you can retrieve the HttpApplication object and the HttpContext:
private void Application_Error(object sender, EventArgs e) { HttpApplication application = (HttpApplication)sender; HttpContext context = application.Context; }The HttpContext is the class that corresponds to the current HttpRequest in process. It is always available during the page lifecycle.
In fact there is a static method on the class:
HttpContext.Current
that retreives the current context, so you can in fact utilise it anywhere.. it doesn't have to be passed in as a method parameter.
When your code is executing in your page/business/data layers at the HttpHandler level, when an exception is encountered the HttpContext object is still current and instantiated.
Therefore the object's properties will still be valid... Request, Response, Session etc.
So it is very strange that these objects do not produce any data when an error happens at this stage of the request life cycle.
(To read more on the application life cycle, here is a great article from MSDN
ASP.NET Life cycle overview )
You therefore, in my opinon, have a particular production issue where the data is not being catpured..
either there is something wrong in the lifce cycle OR your code for capturing is somehow not working due to different settings between dev and live set ups.
Contact me by email via my profile here on the site and I can send you my email address if you wish - if you share the portion of code that is actually processing inside the Application_Error event I might be able to advise if there is a specific code issue.
Otherwise, I am not really a production debugging expert, so cannot advise further on getting to the source of your problem.
What I can tell you is the information SHOULD be available to you.
httpcontext
foreachbiscuit
blog @ http://foreachbiscuit.wordpress.com