うまく機能しているカミソリ サイトがありますが、処理されない例外が発生することがあります。私はそれを追跡しようとしていますが、今のところ、彼らがこれを見ないところで変更したいと思います:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Exception: Test
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
ここに私がこれまでに持っているものがありますが、それはキャッチしません。
Global.asax.cs:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("UnhandledExceptions", "Error", new { controller = "Error", action = "Index" });
routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Account", action = "Logon", id = UrlParameter.Optional });
}
私のErrorController.cs:
using System.Web.Mvc;
namespace SuburbanCustPortal.Controllers
{
public class ErrorController : Controller
{
public ActionResult Index()
{
return View("Error");
}
}
}
エラーを生成するための私のテストコード:
public ActionResult Test()
{
throw new Exception("Test");
}
これは私のweb.configにあります:
<customErrors mode="On" >
<error statusCode="403" redirect="~/Error"/>
<error statusCode="404" redirect="~/Error"/>
<error statusCode="500" redirect="~/Error"/>
</customErrors>
私は何が欠けていますか?
====== 編集 #1 ======
Mike の回答に従って変更を加え、web.config を次のように変更しました。
<customErrors mode="On" defaultRedirect="~/Error/">
</customErrors>
次のメッセージが表示されます。
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Exception: Test
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[Exception: Test]
SuburbanCustPortal.Controllers.HomeController.Test() in D:\Suburban\s\Web Projects\WebPortal\SuburbanCustPortal\Controllers\HomeController.cs:133
lambda_method(Closure , ControllerBase , Object[] ) +79
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +264
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +129
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +826266
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +314
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +825488
System.Web.Mvc.Controller.ExecuteCore() +159
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375
これは、上記のテストを実行しようとしたときに発生する例外です。