I've been playing around with ELMAH in my MVC4 application. I've downloaded ELMAH from Nuget and it sets the configuration for me. I know that ELMAH for MVC will catch errors in controllers, but how about errors else where? For instance error inside Application_Start? I've managed to log errors with ELMAH in the Application_Error but unable to redirect it to MVC 4 error page in the /Shared/ folder. Is even this possible?

有帮助吗?

解决方案

yes - for a local environment, the redirect won't work unless you have the web.config set to customErrors mode="On" defaultRedirect="Error" and then you need to disable the global filter HandleError. Comment out the HandleErrorAttribute line in RegisterGlobalFilters.

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
    //filters.Add(new HandleErrorAttribute());
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top