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?
Asked
Active
Viewed 723 times
1 Answers
0
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());
}

viperguynaz
- 12,044
- 4
- 30
- 41
-
Why do we need to disable the HandleErrorAttribute? – osheh Jan 03 '13 at 06:58
-
Because you are handling errors through Elmah in Application_Error. – viperguynaz Jan 03 '13 at 13:39
-
If you comment out that line then, you want to show a custom error page. How will you do it?. It's not a good solution. You should create a new custom error filter and add that to filters then you can comment out this. – Imrul Mar 16 '13 at 12:18
-
Elmah already had a handler that doesn't need to be registered. You can leave it in, but you'll be getting duplicate entries in ELMAH. – viperguynaz Mar 23 '13 at 01:38