iis8修改500错误页面后保持http code


iis在修改比如403,404,500,502,503等状态的默认错误页面后默认会传递http code为200,不利于问题发现和监控,现在要改完错误页面以后报纸http code。

1.修改C:\Windows\System32\inetsrv\config下的applicationHost.config,标红之处为新添加参数

<httpErrors allowAbsolutePathsWhenDelegated="true" lockAttributes="allowAbsolutePathsWhenDelegated,defaultPath">
<error statusCode="401" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="401.htm" />
<error statusCode="403" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="403.htm" />
<error statusCode="404" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="404.htm" />
<error statusCode="405" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="405.htm" />
<error statusCode="406" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="406.htm" />
<error statusCode="412" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="412.htm" />
<error statusCode="500" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="500.htm" />
<error statusCode="501" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="501.htm" />
<error statusCode="502" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="502.htm" />
</httpErrors>

2.在iis设置页面修改默认错误页面:

按照步骤修改完毕后重启iis即可,查看http code。


Whatever is worth doing is worth doing well.