我有这样的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应用程序之一内,以便继承这些“错误”设置)。

解决方案资源管理器:

〜/您的WebApp


...
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>

关于asp.net - 跳过CustomErrors并转到HttpErrors,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47338967/

10-11 17:00