I have code in the global.asax
file's Application_Error
event which executes when an error occurs and emails details of the error to myself.
void Application_Error(object sender, EventArgs e)
{
var error = Server.GetLastError();
if (error.Message != "Not Found")
{
// Send email here...
}
}
This works fine when I'm running it in Visual Studio, however when I publish to our live server the Application_Error
event does not fire.
After some testing I can get the Application_Error
firing when I set customErrors="Off"
, however setting it back to customErrors="On"
stops the event from firing again.
Can anyone suggest why Application_Error
would not be firing when customErrors
are enabled in the web.config
?