【问题标题】:MVC 3 Custom/Http error pages not shown for View exceptions视图异常未显示 MVC 3 自定义/Http 错误页面
【发布时间】:2012-05-31 21:32:18
【问题描述】:

我在 ASP.NET MVC 3 应用程序中设置了自定义/http 错误,这些错误将显示在错误中。我的Web.Config 的httpErrors 部分如下所示:

    <httpErrors errorMode="Custom" existingResponse="Replace">
        <remove statusCode="400" />
        <remove statusCode="403" />
        <remove statusCode="404" />
        <remove statusCode="408" />
        <remove statusCode="500" />
        <remove statusCode="503" />
        <error statusCode="400" responseMode="ExecuteURL" path="/Error/BadRequest" />
        <error statusCode="403" responseMode="ExecuteURL" path="/Error/Forbidden" />
        <error statusCode="404" responseMode="ExecuteURL" path="/Error/NotFound" />
        <error statusCode="408" responseMode="ExecuteURL" path="/Error/Timeout" />
        <error statusCode="500" responseMode="ExecuteURL" path="/Error/InternalServerError" />
        <error statusCode="503" responseMode="ExecuteURL" path="/Error/ServiceUnavailable" />
    </httpErrors>

我没有设置 customerErrors 设置,因为这不适用于 MVC 和 IIS 7.5。

当代码中发生异常时,一切正常。

但是,当视图中引发异常时 - 它会尝试显示我没有的默认 ~/Views/Shared/Error.cshtml。

可能引发错误的视图可能是这样的:

@Html.Partial("TemplateSection", Model.PreContent)

假设PreContent 为空,TemplateSection 视图会在显示值时失败:@Model.Name

【问题讨论】:

    标签: asp.net-mvc-3


    【解决方案1】:

    我阅读了this article,自从 48 小时前将生成的代码投入生产以来,我没有遇到任何问题。试一试。

    【讨论】:

      猜你喜欢
      • 2011-08-30
      • 2015-03-20
      • 1970-01-01
      • 2011-10-07
      • 2013-08-02
      • 1970-01-01
      • 2020-02-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多