【问题标题】:web.config default error page conflicting with 404 returned from APIweb.config 默认错误页面与 API 返回的 404 冲突
【发布时间】:2015-02-06 14:03:31
【问题描述】:

当调用 API 的 AngularJS 控制器预计会处理 404 时,如何防止 IIS 8 拦截 HTTP 404 错误并处理它们(通过 <httpError><customError>)? API 调用返回的 404 仅表示未找到请求的对象。然而 IIS 似乎拦截了 404 并将其视为错误。

<system.webServer>
  <httpErrors errorMode="DetailedLocalOnly" defaultResponseMode="File" defaultPath="Error.html">
    <remove statusCode="404" />
    <remove statusCode="505" />
    <error statusCode="404" path="Error.html" />
    <error statusCode="505" path="Error.html" />
  </httpErrors>
</system.webServer>

我可以在 web.config(上图)中禁用自定义错误处理,但我仍然想要一个默认的捕获所有错误页面。

【问题讨论】:

    标签: angularjs iis asp.net-web-api custom-error-pages


    【解决方案1】:

    如果您覆盖基本控制器的protected override void OnException(ExceptionContext filterContext),您可以设置filterContext.HttpContext.Response.TrySkipIisCustomErrors = true。这将指示 IIS 忽略您定义的自定义错误。

    有关在控制器中捕获 404 的更多详细信息,请参阅this 文章。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-03
      • 1970-01-01
      • 2016-03-02
      • 1970-01-01
      • 1970-01-01
      • 2011-03-16
      • 1970-01-01
      相关资源
      最近更新 更多