While debugging my MVC 4 application in VS2010 SP1, the Application_Error()
handler was invoked but Server.GetLastError()
was null.
protected void Application_Error()
{
var exception = Server.GetLastError();
// exception is null. How is that possible?
}
MSDN states Application_Error
is
called if an unhandled exception occurs anywhere in your ... application... You can get information about the most recent error from the
GetLastError
method.
The MSDN docs for Server.GetLastError
() states
Return value: The previous exception that was thrown.
How can I possibly be in a state where Application_Error()
was called but Server.GetLastError()
returns null?
Are you using custom error handling in your web.config? I believe that if the browser issues a redirect, the previous exception will be lost. Take a look at this answer and see if your situation is similar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With