I have a C# web forms ASP.NET 4.0 web application that uses Routing for URLs for some reason custom errors defined in the system.web section of my web.config is entirely ignored and it will fall back the IIS errors.
This gets entirely ignored
<system.web>
<customErrors mode="On">
<error statusCode="500" redirect="~/Error" />
<error statusCode="404" redirect="~/404" />
<error statusCode="403" redirect="~/Error" />
</customErrors>
</system.web>
This part takes over
<system.webServer>
<httpErrors>
<!--<clear />-->
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" path="/App1/404" responseMode="Redirect" />
<error statusCode="500" prefixLanguageFilePath="" path="/App1/Error" responseMode="Redirect" />
</httpErrors>
</system.webServer>
This would be a minor inconvenience except that by the fact it falls back to IIS native instead of my application it completely circumvents Elmah logging my 404 exceptions correctly.
Edit: Just to avoid any suggestions of such I only added the httpErrors configuration after customErrors stopped working so I would have anything.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…