HttpModule: how to handle HttpApplication errors without HttpContext?

I am faced with a particularly interesting situation. I currently have a general error handling procedure. I recently noticed some strange behavior: HttpApplication.Error will fire, but HttpContext.Current will be empty. This is the corresponding bit in my HttpModule:

 public void Init(HttpApplication context) { context.Error += context_Error; context.PostMapRequestHandler += context_PostMapRequestHandler; } void context_PostMapRequestHandler(object sender, EventArgs e) { var aux = HttpContext.Current.Handler as Page; if (aux != null) aux.Error += context_Error; } void context_Error(object sender, EventArgs e) { _localLog.Add("HttpApplication error handler reached."); try { if (HttpContext.Current == null) { _localLog.Add("No HttpContext."); } else { var objError = HttpContext.Current.Server.GetLastError(); if (objError == null) { _localLog.Add("GetLastError(): no error."); return; } //[Proper error handler follows here...] } } } 

And an intriguing event would look like this:

enter image description here

My first assumption is that an exception is thrown into the thread out of context.

In any case, how can I lock it correctly?

+7
source share

No one has answered this question yet.

See related questions:

2058
How to get consistent byte representation of strings in C # without manually specifying an encoding?
1786
How to create an Excel file (.XLS and .XLSX) in C # without installing Microsoft Office?
264
Timed out. The wait period expires before the operation is completed or the server is not responding. Application has been discontinued
4
Application_Start will not work when inheriting Global.asax from the Global.asax provider
3
ASP.NET request is not available in this context
2
First start of ASP site and getting server error in "/" application
one
Custom error handling in DNN 7?

All Articles