4
I have been finding a particularly interesting situation. I have a generic error handling routine implemented within a HttpModule
, and recently I noticed a strange behavior: The event HttpApplication.Error
is fired, but HttpContext.Current
is null
.
This is the relevant part of 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 the event appears as follows:
One possibility is that the Exception is being generated in a thread out of context.
Anyway, how can I intercept this error in order to treat it?
Interesting point, Ricardo! Thanks for the suggestion, I will test the cast for Httpapplication.
– OnoSendai