IIS 8.5 – getting error when returning static 404 file

500-errorhttp-status-code-404iisiis-8iis-8.5

IIS8.5 > Sites > mysite > Error Pages > 404

  • Select "Insert content from static file into the error response".

  • Uncheck "Try to return the error file in the client language".

  • Enter path to "notfound.html", I've verifieed it is there.

When I visit a page I know isn't there I get:

The page cannot be displayed because an internal server error has occurred.

Why aren't I getting my custom 404 file?

I don't think it's a permission thing, I've tried moving "notfound.html" to several places, one of which is the actual site wwwroot folder which serves the rest of the site.

Best Answer

This error is generated because an absolute path is detected in web.config.

Absolute physical path (like C:\path\to\notfound.html) is not allowed in system.webServer/httpErrors section in web.config file.

Now you have 2 solutions :


1. Allow physical path in ApplicationHost.config file

By default this file is located in %SystemRoot%\system32\inetsrv\config

Locate this file and Edit it

Search for section <httpErrors ..... >

Then add directive allowAbsolutePathsWhenDelegated="true", like the following :

<httpErrors lockAttributes="allowAbsolutePathsWhenDelegated,defaultPath" allowAbsolutePathsWhenDelegated="true">
   ....
   ....
</httpErrors>

Save the file, should work !


2. Use relative path

Relative path means that you will have to store your custom error pages in the root folder of the given Web Site.

Then, go to IIS > Sites > mysite > Error Pages > 404

And setup your custom error page like this :

enter image description here

Click OK, should work !


EDIT :

However, note that :

  • Solution 1 sends a 404 Not Found response
  • Solution 2 sends a 200 OK response