2

可能重复:
如何处理应用程序启动时发生的 ASP.NET 应用程序错误以及 MVC 视图中的传输和显示错误?

我们目前正在使用 BaseController 中的 HandleError 属性处理 ASP.NET MVC 2 应用程序中的错误。

Web.config 的自定义错误部分如下所示,它可以很好地处理源自控制器的所有未处理异常

<customErrors mode="On" defaultRedirect="error.aspx">
  <error statusCode="404" redirect="~/error/not-found"/>
</customErrors>

Error.aspx 位于 /Views/Shared 文件夹下,该文件夹是继承自 HandleErrorInfo 的视图

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="ViewPage<HandleErrorInfo>" %>

我们在 Global.asax 的 Application_Start 事件处理程序中有以下代码

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());
    Bootstrapper.Initialize();
    ControllerBuilder.Current.SetControllerFactory(new CustomControllerFactory(logger));
    RegisterRoutes(RouteTable.Routes);
}

Bootstrapper.Initialize() 在配置 Structuremap 注册表时抛出了一些错误。此错误不会调用 web.config 中指定的 Error.aspx,但我必须使用 Application_Error 事件处理程序单独处理它们。

对于在正常 ASP.NET MVC 管道之外引发的错误,显示相同 error.aspx 的最佳方法是什么?

4

0 回答 0