web.config errors fail with responseMode="File"
Asked Answered
C

1

12

According to Microsoft's documentation, for static (i.e. HTML) content, web.config should read responseMode="File" for each error.

Currently, my web.config includes

<httpErrors errorMode="Custom">
    <!-- remove statusCodes -->
    <error statusCode="404" path="/error/404.html" responseMode="ExecuteURL" />
</httpErrors>

This returns the correct custom error page, but returns a 200 OK status code.

When I change "ExecuteURL" to "File", my server does return a 404, but the custom error page is not displayed. Instead, I get the message "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

How is web.config supposed to read, to return a static file, but also a 404?

Edit: removed <customErrors> questions after learning that that tag is for IIS <= 6.0

Carlock answered 8/7, 2013 at 18:32 Comment(1)
You should put error pages in the root of the project.Carny
C
30

I was figthing with exactly same problem pretty long time. Now I found out by accident that the problem is in the slash character.

this is working for me - no beginning slash and use \ instead of /

  <error statusCode="404" path="Static\WebServer\PageNotFound.htm" responseMode="File" /> 
Creep answered 13/5, 2014 at 9:50 Comment(1)
Indeed, if you have a leading slash it will not work and will just give back the generic internal error page. I was doing path="\PageNotFound.html" and it really just needed path="PageNotFound.html".Natie

© 2022 - 2024 — McMap. All rights reserved.