HandleErrorAttribute not working

asp.net-mvc, asp.net-mvc-3

Solution

Much though I hate to disagree with anything Darin says, he is wrong on this one.

There is no problem with setting the properties (that's the way you are supposed to do it).

The only reason your original code didn't work as expected is because you have the `Order` set wrong.

See MSDN:

The OnActionExecuting(ActionExecutingContext), OnResultExecuting(ResultExecutingContext), and OnAuthorization(AuthorizationContext) filters run in forward order. The OnActionExecuted(ActionExecutedContext), OnResultExecuting(ResultExecutingContext), and OnException(ExceptionContext) filters run in reverse order.

So your generic `AllOtherExceptions` filter needs to be the lowest `Order` number, not the highest.

Hopefully that helps for next time.

Problem

I have started an MVC 3 template project in VS10 and modified global.asax.cs as such: ``` public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute { ExceptionType = typeof(DivideByZeroException), View = "DivideByZeroException", Order = 1 }); filters.Add(new HandleErrorAttribute { View = "AllOtherExceptions", Order = 2 }); } ``` To web.config I added: ``` <customErrors mode="On"> ``` Then created the corresponding views and finally added a DivideByZero-throw to one of the actions. The result: The view AllOtherExceptions is rendered.

Original source

Related problems