重複の可能性:
アプリケーションの起動時に発生するASP.NETアプリケーションエラーとMVCビューでの転送および表示エラーを処理するにはどうすればよいですか?
現在、BaseControllerのHandleError属性を使用して、ASP.NETMVC2アプリケーションのエラーを処理しています。
Web.configのカスタムエラーセクションを以下に示します。これは、コントローラーから発生するすべての未処理の例外を正常に処理します。
<customErrors mode="On" defaultRedirect="error.aspx">
<error statusCode="404" redirect="~/error/not-found"/>
</customErrors>
Error.aspxは、HandleErrorInfoから継承したビューである/ Views/Sharedフォルダーの下に配置されます。
<%@ 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.NETMVCパイプラインの外部で発生したエラーに対して同じerror.aspxを表示するための最良の方法は何ですか?