IIS 7 returns HTTP 200 on custom 404 error page

Solution 1:

Switch to using responseMode="File" however the trick with this is going to be using relative file paths unless you unlock or set to true system.webServer/httpErrors allowAbsolutePathsWhenDelegated.

Example web.config excerpt:

<httpErrors>
    <remove statusCode="404" subStatusCode="-1" />
    <error statusCode="404" prefixLanguageFilePath="" path="error\404.htm" responseMode="File" />
</httpErrors>

Solution 2:

When using executeURL, the file should be something that renders dynamically (a la .asp). The file executed must contain a script that sets the response status code.

Example:

  1. Change your 404.htm to 404.asp
  2. Save the following code at the top of the 404.asp:

<% response.status = "404 Page Not Found" %>