【问题标题】:Can a "MVC 5 route" be used as a path in an error element in system.webServer httpErrors section in web.config?是否可以将“MVC 5 路由”用作 web.config 中 system.webServer httpErrors 部分的错误元素中的路径?
【发布时间】:2014-02-10 00:59:32
【问题描述】:

“MVC 5 路由”能否在 web.config 的 system.webServer httpErrors 部分的 error 元素中用作 path

<configuration>
...other config stuff...
<system.webServer>
    <httpErrors errorMode="Custom">
      <remove statusCode="404"/>
      <error statusCode="404" path="/Error/NotFound" responseMode="ExecuteURL"/>
    </httpErrors>
  </system.webServer>
</configuration>

【问题讨论】:

  • 是的,responseMode 设置对于确保在错误条件下启动正确的路由很重要。您看到了什么结果?
  • 那么 ExecuteURL 不仅适用于 .aspx 页面吗? MSDN/IIS 文档对此不是很清楚。 ExecuteURL 提供在路径属性中为自定义错误指定的动态内容(例如,.asp 文件)。如果 responseMode 设置为 ExecuteURL,则路径值必须是服务器相对 URL。数值为 1

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


【解决方案1】:

是的,你可以这样做。使用responseMode="ExecuteURL" IIS 在内部“重定向”(发送对给定 URL 的请求)并将结果写入响应。

您可能还想将httpErrors 中的existingResponse 属性设置为Replace

请注意:

出于体系结构的原因,IIS 7.0 只能在 URL 位于同一个应用程序池中时才能执行它。使用重定向功能在不同的应用程序池中执行自定义错误。

【讨论】:

    猜你喜欢
    • 2016-10-03
    • 1970-01-01
    • 1970-01-01
    • 2020-01-22
    • 1970-01-01
    • 1970-01-01
    • 2015-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多