【问题标题】:Disable default ASP.NET error pages, show default IIS error pages instead (remote only)禁用默认 ASP.NET 错误页面,改为显示默认 IIS 错误页面(仅限远程)
【发布时间】:2017-10-08 17:33:54
【问题描述】:

我可以只为远程请求禁用默认的 ASP.NET 错误页面,而不是来自 IIS 的错误页面吗?基本上是HttpResponse.TrySkipIisCustomErrors,但反过来。

我尝试调用Response.Clear() 以从响应中删除默认的ASP.NET 错误页面,并使用existingResponse="PassThrough" 配置我的IIS 错误页面。虽然这会阻止显示默认的 ASP.NET 错误页面,但它不会显示 IIS 错误页面。 (I've opened a separate question about PassThrough)

【问题讨论】:

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


    【解决方案1】:

    第一个解决方案: 对于 IIS 7+,是使用其中的标记来定义错误页面行为,而不是每个页面/请求,而是全局用于 web.config 中的应用程序,如下所示:

    <system.webServer>
      <httpErrors errorMode="Custom"/>
      [...]
    </system.webServer>
    

    第二个解决方案: 禁用此行为是在错误控制器中设置 Response.TrySkipIisCustomErrors,如下所示:

    [HandleError]
    public class ErrorController : Controller
    {
      public ActionResult NotFound()
      {
        Response.TrySkipIisCustomErrors = true;
        Response.StatusCode = (int)HttpStatusCode.NotFound;
        return View("NotFound");
      }
    
    }
    

    【讨论】:

    • 1.我已经在使用&lt;httpErrors&gt;。 ASP.NET 推翻了这些。 2.TrySkipIisCustomErrors与我想要实现的相反。我想要 IIS 错误,而不是 ASP.NET 错误。
    猜你喜欢
    • 2012-07-15
    • 1970-01-01
    • 2011-01-01
    • 2011-10-04
    • 2020-07-24
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 2019-03-16
    相关资源
    最近更新 更多