我有像这样的web.config设置
<customErrors mode="On" >
<error statusCode="404" redirect="~/404" />
<error statusCode="403" redirect="~/500" />
<error statusCode="500" redirect="~/500" />
</customErrors>
并为httperrors
<httpErrors errorMode="Custom" >
<error statusCode="400" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\bad_request.html" />
<remove statusCode="401" subStatusCode="-1" />
<error statusCode="401" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\unauthorized.html" />
<remove statusCode="403" subStatusCode="-1" />
<error statusCode="403" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\forbidden.html" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\not_found.html" /><remove statusCode="405" subStatusCode="-1" />
<error statusCode="405" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\method_not_allowed.html" /><remove statusCode="406" subStatusCode="-1" />
<error statusCode="406" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\not_acceptable.html" />
<error statusCode="407" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\proxy_authentication_required.html" /><remove statusCode="412" subStatusCode="-1" />
<error statusCode="412" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\precondition_failed.html" />
<error statusCode="414" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\request-uri_too_long.html" /><error statusCode="415" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\unsupported_media_type.html" />
<remove statusCode="500" subStatusCode="-1" /><error statusCode="500" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\internal_server_error.html" />
<remove statusCode="501" subStatusCode="-1" /><error statusCode="501" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\not_implemented.html" />
<remove statusCode="502" subStatusCode="-1" /><error statusCode="502" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\bad_gateway.html" />
<error statusCode="503" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\maintenance.html" />
</httpErrors>
在404错误.跳过404页面并转到.aspxerrorpath = page.aspx
和写作
您要查找的资源已被删除,名称已更改或暂时不可用.
我想显示我自定义的404,500错误页面.有什么不对
最佳答案 简而言之,在生产中可以完全摆脱“system.web – > customErrors”部分,这几乎是出于兼容性目的而保留(查看
What is the difference between customErrors and httpErrors?线程以了解更多信息),以及指定重定向的部分.然后,仅在“system.webServer – > httpErrors”部分中指定必要的重定向和自定义错误页面.确保这些HTML文件存在于Web服务器上,并且可以通过相对路径获得(或者这些页面存在于同一Web服务器上的一个父Web应用程序中,以便继承这些“错误”设置).
Solution Explorer:
〜/ YourWebApp
> ……
> not_found.html
> Web.config
Web.config(用于404状态代码错误):
<!--Dev: For Visual Studio Mode-->
<system.web>
<customErrors mode="On">
<error statusCode="404" redirect="~/not_found.html" />
</customErrors>
</system.web>
<!--Prod: For IIS Mode-->
<system.webServer>
<httpErrors errorMode="Custom">
<!--<error statusCode="404" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\not_found.html" />-->
<error statusCode="404" path="~/not_found.html" responseMode="Redirect" />
</httpErrors>
</system.webServer>