IIS服务器web.config设置404 403 500错误转发
一、customErrors和httpErrors的区别
customErrors 用于捕捉ASP.NET触发的错误,静态html页面或目录不存在等错误,不会被捕捉到。
httpErrors 用于捕捉IIS触发的错误,IIS7+版本才支持。
二、配置文件
1.IIS7+:
<system.web><customErrorsmode="On"defaultRedirect="Error.html"><errorstatusCode="403"redirect="/Error403"/><errorstatusCode="404"redirect="/Error404"/><errorstatusCode="500"redirect="/Error500"/></customErrors></system.web>
<system.webServer><httpErrorserrorMode="Custom"existingResponse="Auto"defaultResponSEMode="ExecuteURL"><removestatusCode="403"/><removestatusCode="404"/><removestatusCode="500"/><!--path不能使用~/开头,直接/--><errorstatusCode="403"responseMode="ExecuteURL"path="/Error403"/><errorstatusCode="404"responseMode="ExecuteURL"path="/Error404"/><errorstatusCode="500"responseMode="ExecuteURL"path="/Error500"/></httpErrors></system.webServer>
静态页面配置
<system.webServer><httpErrorserrorMode="Custom"existingResponse="Auto"defaultResponseMode="File"><removestatusCode="404"/><errorstatusCode="404"path="404.html"/></httpErrors></system.webServer>
2.IIS6.0
配置customErrors
配置httpErrors