IIS 8.5 - getting error when returning static 404 file

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

I snooped around and found that there is a thing called "allowAbsolutePathsWhenDelegated" which is set to "false" by default.

IIS8.5 > Sites > mysite > Management > Configuration Editor > system.webServer/httpErrors

However the value is locked and can't be edited there. So I clicked the root in the tree and could edit it there.

IIS8.5 > Management > Configuration Editor > system.webServer/httpErrors

Note that the root is not actually named "IIS8.5", it's named after your computer name.

So after allowAbsolutePathsWhenDelegated was set to true everything worked fine. A different solution would have been to put the static file inside my site's wwwroot folder and just enter the name of it as the 404 error page (though in my case it's better with a absolute path instead of a relative one).

What bugs me is that there is no mention anywhere on the "Error Pages" screen about this default restriction. It doesn't say anything about the path having to be relative to your site root and since the default is NOT relative (it's in the inetpub folder) you assume an absolute path would work fine.

Hopefully Microsoft will fix this interface issue in a later version. Just be more clear about any restrictions in the input fields, please.