I have the following in my Global.asax
which is meant for handling errors:
void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
if (exception != null)
{
//Log
if (HttpContext.Current.Server != null)
{
HttpContext.Current.Server.Transfer("/siteerror.aspx");
}
}
}
This works for the most part, but sometimes does not get into Server.Transfer
. For some reason HttpContext.Current.Server
is null. I figured out where this happens: when errors occur in a user control and in my business logic classes.
Am I missing something here?