Asp.net 使用httpErrors时,我可以告诉IIS 8.5返回404吗?
我正在一个运行IIS8.5的(Web表单)网站上工作,目前正在为404和500设置错误处理 我已经有了Asp.net 使用httpErrors时,我可以告诉IIS 8.5返回404吗?,asp.net,iis-8.5,custom-errors,integrated-pipeline-mode,Asp.net,Iis 8.5,Custom Errors,Integrated Pipeline Mode,我正在一个运行IIS8.5的(Web表单)网站上工作,目前正在为404和500设置错误处理 我已经有了system.webcustomErrors设置,但是由于我们在集成模式/更新版本的IIS中运行,它正在从system.webServerhttpErrors中提取 使用IIS GUI,我选择在站点上用静态HTML文件替换标准IIS错误页面: <httpErrors errorMode="Custom"> <remove statusCode="404" subStat
system.web
customErrors
设置,但是由于我们在集成模式/更新版本的IIS中运行,它正在从system.webServer
httpErrors
中提取
使用IIS GUI,我选择在站点上用静态HTML文件替换标准IIS错误页面:
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath=""
path="/problem.html" responseMode="ExecuteURL" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="500" prefixLanguageFilePath=""
path="/problem.html" responseMode="ExecuteURL" />
</httpErrors>
不幸的是,当显示正确的错误页面时,返回的不是404而是200,对于500个错误,返回302后跟200
对于旧版本的IIS,或那些未在集成模式下运行的IIS,可以在customErrors
元素上设置redirectMode=“ResponseRewrite”
,这将解决此问题
我已尝试将httpErrors
上的existingResponse
设置为所有三个可用选项,并尝试更新设置responseMode=“File”
,但这些都没有改变
有没有什么方法可以为客户做类似的事情?还是我一直在将错误指向ASP.NET页面并从那里返回相应的错误
谢谢 要解决此问题,您可以将此配置设置到WebConfig文件中的
。像这样:
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<clear/>
<error statusCode="404" path="/WebForms/Index.aspx" responseMode="File"/>
</httpErrors>
<system.webServer/>
responseMode=File
将保留原始错误代码,并显示静态页面 看起来是把existingResponse=“Replace”
和responseMode=“File”
结合起来的。但是,对于静态HTML,我还必须删除初始斜杠,path=“problem.HTML”
(否则返回的是白色页面错误)。我还必须清除customErrors
元素(模式刚刚设置为RemoteOnly
),您还可以在httpErrors
元素上使用defaultResponseMode=“File”
,以避免在多个error
节点上声明它