如何使用 httpErrors 添加默认错误页面 [英] How to add a default error page using httpErrors

查看:26
本文介绍了如何使用 httpErrors 添加默认错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功添加自定义 404 页面.我想要做的是创建另一个自定义错误页面,当出现 404 以外的任何错误时显示该页面.例如500、403等

i have successfully added a custom 404 page. what I want to do is to create another custom error page that is displayed when there is any error other than 404. e.g. 500, 403 etc.

这就是我现在在 webconfig 中的内容

this is what I have right now in webconfig

<httpErrors errorMode="Custom" existingResponse="Replace">
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" path="/404.aspx" responseMode="ExecuteURL"/>
    </httpErrors>

推荐答案

哦,天哪.我不敢相信我找不到这个简单问题的正确答案!尽管如此,在阅读文档和调试 2 小时后,我找到了.

Oh, my. I cannot believe I could not find a proper answer for this simple question! Nevertheless, after 2 hours of reading the docs and debugging, I found it.

<httpErrors errorMode="Custom" existingResponse="Auto" defaultResponseMode="ExecuteURL" defaultPath="/App/Error"> <!-- Do not include ~, this was my issue all long -->
  <clear/> <!-- so that IIS provided error pages are skipped -->
  <!-- add those which you like to provide a view of yours -->
  <error path="/App/Http404" responseMode="ExecuteURL" statusCode="404"/>
  <error path="/App/Http503" responseMode="ExecuteURL" statusCode="503"/>
</httpErrors>

请注意, 配置 IIS,而 配置 ASP.NET 和一些旧版本的 IIS (<=6?).

Beaware that <httpErrors> configures IIS, while <customErrors> configures ASP.NET and some older versions of IIS (<=6?).

这篇关于如何使用 httpErrors 添加默认错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆