So I have a very basic site that's hosted in IIS (for now just straight raw html with no .Net code)
In my web.config I have the following:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/404.html" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>
This was added into the web.config by the IIS manager – and it reflects what I've found online as the valid configuration for 404 errors to redirect to my custom 404 page.
However I still get the IIS generated HTTP Error 404.0 - Not Found
page back whenever I go to a page that doesn't exist.
Any ideas what I'm doing wrong here?
Setup:
- IIS 10/IIS 8.5 (Tested on both)
- Windows 10/Windows 8.1 (Tested on both)
- DefaultAppPool
- Chrome, Edge, Internet Explorer, Firefox (All latest)
Best Answer
Whenever a configuration element in my IIS config files doesn't produce the behavior I expect, the first place I look is always the official (and quite comprehensive) IIS.net Configuration Reference documentation.
If you browse to the
httpErrors
page and scroll down to "Attributes", you'll find that theerrorMode
attribute defaults to a value of "DetailedLocalOnly", and what that implies:Aha! If your request results in an error page while browsing locally, you get a detailed error page rather than your custom one!
Just below, there's an entry for a
Custom
value:And that's it, just add the attribute
errorMode
with a value ofCustom
to thehttpErrors
node to override the default: