Application_Error never reached for 404, if URL does not contain an existing controller
<p>I have this code in my global.asax:</p>

<pre><code>protected void Application_Error(object sender, EventArgs e)
{
    var exception = Server.GetLastError();
    var httpException = exception as HttpException;
    //...
}
</code></pre>

<p>If I call a URL like this, where <code>NonExistingNonesense</code> does not exist:</p>

<pre><code>localhost/ExistingArea/ExistingController/NonExistingNonesense
</code></pre>

<p>Everything is fine. (The code from my global.asax will be called)</p>

<p>But if I call a url like this:</p>

<pre><code>localhost/NonExistingNonesense
</code></pre>

<p>The code never reach the <code>Application_Error</code> method.</p>

<p>What could be the problem?</p>

<hr>

<p>I have this in my web.config:</p>

<pre><code>&lt;system.web&gt;
  &lt;customErrors mode="On"&gt;&lt;/customErrors&gt;
  &lt;!-- ... --&gt;
&lt;/system.web&gt;
&lt;system.webServer&gt;
  &lt;httpErrors existingResponse="PassThrough"/&gt;
  &lt;!-- ... --&gt;
&lt;system.webServer&gt;
</code></pre>

<hr>

<p>Please note:</p>

<p>I know it is possible with</p>

<pre><code>&lt;error statusCode="404" responseMode="ExecuteURL" path="/Error/PageNotFound" /&gt;
</code></pre>

<p>The problem is, I need to pass some exception context to my view, so I want to handle this by code.</p>