web.config errors fail with responseMode=“File”

浪子不回头ぞ 提交于 2019-12-21 03:58:07

问题


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


回答1:


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" /> 


来源:https://stackoverflow.com/questions/17533579/web-config-errors-fail-with-responsemode-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!