这些是web.config中的代码:
<system.web> <customErrors mode="Off" > </customErrors> </system.web> <system.webServer> <httpErrors errorMode="Custom" existingResponse="Replace"> <clear /> <error statusCode="404" prefixLanguageFilePath="" path="/ResourceNotFound" responseMode="ExecuteURL" /> <error statusCode="500" prefixLanguageFilePath="" path="/ResourceNotFound" responseMode="ExecuteURL" /> </httpErrors> </system.webServer>
但不是手动添加400,401,403 ….等所有错误代码… …
我们可以设置它将所有错误重定向到相同的URL而不键入所有错误代码吗?
<error statusCode="400" ..... <error statusCode="401" ..... <error statusCode="403" ..... <error statusCode="404" ..... <error statusCode="xxx" ....
解决方法
试试这个,
<system.webServer> <httpErrors errorMode="DetailedLocalOnly" defaultResponseMode="File" > <remove statusCode="500" /> <error statusCode="500" prefixLanguageFilePath="C:\Contoso\Content\errors" path="500.htm" /> </httpErrors> </system.webServer>
和
<httpErrors existingResponse="Replace" defaultResponseMode="ExecuteURL" errorMode="Custom"> <remove statusCode="404" /> <error statusCode="404" path="/ErrorPages/Oops.aspx" responseMode="ExecuteURL"/> <remove statusCode="401" /> <error statusCode="401" path="/Account/Login.aspx" responseMode="ExecuteURL"/> <remove statusCode="501"/> <error statusCode="501" path="/ErrorPages/Oops.aspx" responseMode="ExecuteURL"/> <remove statusCode="411"/> <error statusCode="411" path="/ErrorPages/Oops.aspx" responseMode="ExecuteURL"/> <remove statusCode="403"/> <error statusCode="403" path="/ErrorPages/Oops.aspx" responseMode="ExecuteURL"/> </httpErrors>
更多关于这http://www.iis.net/configreference/system.webserver/httperrors