【问题标题】:404.html, ASP.NET MVC root directory404.html,ASP.NET MVC 根目录
【发布时间】:2015-02-01 01:51:19
【问题描述】:

我在 MVC 中找到了几个错误页面的解决方案。大多数解决方案都基于路由和单独的错误控制器。但我需要一个最简单的基于 html 的错误页面,根本不需要预处理。

有没有办法绕过路由文件将 404.html、403.html 和 500.html 文件作为静态内容提供?

我已将这三个 html 文件放在我的 ~/Views/Shared/ 中,并将以下文件放在 web.config 中,即应用程序根目录中的一个:

<system.web>
  <customErrors mode="Off" />
    <error redirect="~/500.html" statusCode="500" />
    <error redirect="~/404.html" statusCode="404" />
    <error redirect="~/403.html" statusCode="403" />
  </customErrors>
</system.web>

但它在本地和远程它在上述 XML 的第三行抛出错误,它使用默认的 IIS 主题抛出 500 内部错误。

哪个目录被认为是提供静态 HTML 文件的根目录?

【问题讨论】:

  • 你试过根目录吗?
  • 你的意思是项目的根目录?是的,那也没用。

标签: asp.net asp.net-mvc asp.net-mvc-5


【解决方案1】:

CustomErrors 模式应为“On”或“RemoteOnly”,并且不应关闭 CustomErrors 标签 - 正如@Preyash Desia 所述

<customErrors mode="On">

【讨论】:

  • 你是在问还是在回答?
  • 同意,这不是最好的回答方式。感谢您的反馈意见。答案已更新。
【解决方案2】:
    <system.web>
  <customErrors mode="Off">
    <error redirect="~/500.html" statusCode="500" />
    <error redirect="~/404.html" statusCode="404" />
    <error redirect="~/403.html" statusCode="403" />
  </customErrors>
</system.web>

第 2 行末尾有多余的“/”,它的 xml 无效;去掉它。

【讨论】:

    猜你喜欢
    • 2014-05-20
    • 1970-01-01
    • 2012-08-20
    • 1970-01-01
    • 2013-10-17
    • 1970-01-01
    • 2011-11-22
    • 2011-09-14
    • 2011-04-14
    相关资源
    最近更新 更多