【问题标题】:CustomErrors on doesn't work on productionCustomErrors on 不适用于生产
【发布时间】:2012-01-13 18:06:11
【问题描述】:

我有 asp.net mvc 3 应用程序。

当用户传递不存在对象的 id 时,我以这种方式返回 404 视图:

Response.StatusCode = 404;
return View("404");

本地一切正常,我有我的自定义错误页面。但在生产中,我有标准的 asp.net 404 页面。我尝试将 customErrors 设置为“on”或“off”——结果是一样的。

【问题讨论】:

    标签: asp.net-mvc error-handling


    【解决方案1】:
    <system.webServer>
        ...
        <httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" prefixLanguageFilePath="" 
                path="/errors/404" responseMode="ExecuteURL" />
        </httpErrors>
    

    此外,还有一种新方法可以从操作方法返回 404:

    // Response.StatusCode = 404;
    // return View("404");
    return HttpNotFound();
    

    【讨论】:

      【解决方案2】:

      在这里找到解决方案:Routing for custom ASP.NET MVC 404 Error page

      在 web config 的 system.webServer 部分下设置另一个魔法设置:

      <httpErrors errorMode="Detailed" />
      

      【讨论】:

        猜你喜欢
        • 2016-11-14
        • 1970-01-01
        • 2013-07-13
        • 2018-03-15
        • 2016-08-30
        • 2021-05-04
        • 2018-02-22
        • 2015-09-07
        • 2016-11-08
        相关资源
        最近更新 更多