且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 httpErrors 添加默认错误页面

更新时间:2023-12-01 21:48:46

哦,天哪.我不敢相信我找不到这个简单问题的正确答案!尽管如此,在阅读文档和调试 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 (

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