Raised Application_Error but no exception

When debugging my MVC 4 application in VS2010 SP1, the Application_Error() handler was Server.GetLastError() , but Server.GetLastError() was empty.

 protected void Application_Error() { var exception = Server.GetLastError(); // exception is null. How is that possible? } 

MSDN Status Application_Error is

thrown if an unhandled exception occurs anywhere in your application ... You can get information about the most recent error from the GetLastError method.

MSDN Server.GetLastError for Server.GetLastError () states

Return value: previous exception that was thrown.

How can I be in the state where Application_Error() was called, but Server.GetLastError() returns null?

+4
source share
1 answer

Do you use custom error handling in your web.config? I believe that if the browser issues a redirect, the previous exception will be lost. Take this answer and see if your situation is similar.

+2
source

All Articles