web.config 自定义 httpErrors 不重定向... "The page cannot be displayed because an internal server error has



我正在尝试让自定义错误页面无效。这个配置是根据我在网上找到的样本改编的。使用GoDaddy托管的IIS 7.0。

下面的代码显示"由于发生内部服务器错误,无法显示页面",而不是重定向。

<configuration>  
<system.webServer>
<httpErrors>
<remove statusCode="401" subStatusCode="-1" />
<remove statusCode="403" subStatusCode="-1" />      
<remove statusCode="404" subStatusCode="-1" />                
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="401" path="http://www.mywebsite.com/error.html" responseMode="Redirect" />
<error statusCode="403" path="http://www.mywebsite.com/error.html" responseMode="Redirect" />
<error statusCode="404" path="http://www.mywebsite.com/error.html" responseMode="Redirect" />                
<error statusCode="500" path="http://www.mywebsite.com/error.html" responseMode="Redirect" />
</httpErrors>
</system.webServer>
<system.web>
<customErrors mode="On"/>
</system.web>
</configuration>

此问题有时会发生在共享托管计划中。看见https://forums.asp.net/t/1894946.aspx?Not+获取+自定义+错误+页面,最后一篇:

"您不能在404错误页面之外修改Windows共享主机计划上的HTTP错误页面,这就是您遇到问题的原因">

所以,如果你有这样的东西:

<httpErrors errorMode="Custom" existingResponse="Replace">
<clear />
<error statusCode="400" responseMode="Redirect" path="/Errors/404error.html" />
<error statusCode="403" responseMode="Redirect" path="/Errors/404error.html" />
<error statusCode="404" responseMode="Redirect" path="/Errors/404error.html" />
<error statusCode="500" responseMode="Redirect" path="/Errors/404error.html" />
</httpErrors>

你会得到错误"页面无法显示,因为发生了内部服务器错误。"但如果你将其更改为:

<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" />
<error statusCode="404" responseMode="Redirect" path="Errors404error.html"/>            
</httpErrors>

它会起作用的。

关于GoDaddy上为什么会发生这种情况的完整讨论可以在这个旧论坛上找到:https://web.archive.org/web/20130131011933/https://support.godaddy.com/groups/web-hosting/forum/topic/customerhttp-error-pages-on-4gh-windows-shared-hosting/。

为什么你的自定义错误可能不起作用,还有很多其他问题,但这个特定的错误似乎没有得到很好的记录,所以我想我应该在这里为其他人发布它。

相关内容

最新更新