问题描述
根据 Microsoft的文档,对于静态(即HTML)内容,则每个错误的web.config均应读取responseMode="File"
.
According to Microsoft's documentation, for static (i.e. HTML) content, web.config should read responseMode="File"
for each error.
当前,我的web.config包括
Currently, my web.config includes
<httpErrors errorMode="Custom">
<!-- remove statusCodes -->
<error statusCode="404" path="/error/404.html" responseMode="ExecuteURL" />
</httpErrors>
这将返回正确的自定义错误页面,但返回200 OK状态代码.
This returns the correct custom error page, but returns a 200 OK status code.
当我将"ExecuteURL"更改为"File"时,服务器确实返回404,但是未显示自定义错误页面.相反,我收到消息您要查找的资源已被删除,名称已更改或暂时不可用."
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."
web.config应该如何读取,返回静态文件以及404?
How is web.config supposed to read, to return a static file, but also a 404?
编辑:在得知该标记适用于IIS< = 6.0
removed <customErrors>
questions after learning that that tag is for IIS <= 6.0
推荐答案
很长时间以来,我一直在思考完全相同的问题.现在我偶然发现问题出在斜线字符中.
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" />
这篇关于web.config错误失败,响应模式=“文件".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!