I have this code in my global.asax:
protected void Application_Error(object sender, EventArgs e)
{
var exception = Server.GetLastError();
var httpException = exception as HttpException;
//...
}
If I call a URL like this, where NonExistingNonesense
does not exist:
localhost/ExistingArea/ExistingController/NonExistingNonesense
Everything is fine. (The code from my global.asax will be called)
But if I call a url like this:
localhost/NonExistingNonesense
The code never reach the Application_Error
method.
What could be the problem?
I have this in my web.config:
<system.web>
<customErrors mode="On"></customErrors>
<!-- ... -->
</system.web>
<system.webServer>
<httpErrors existingResponse="PassThrough"/>
<!-- ... -->
<system.webServer>
Please note:
I know it is possible with
<error statusCode="404" responseMode="ExecuteURL" path="/Error/PageNotFound" />
The problem is, I need to pass some exception context to my view, so I want to handle this by code.