asp.net-mvcasp.net-mvc-3handleerror

ASP.Net MVC 3 - Order in HandleError attribute seems to work backwards?


Problem: When I use the Order property of the HandleError attribute, the highest order number gets applied first, as opposed to the lowest first.

Details

I want to set up my controller to handle exceptions in this way:

Using the default MVC project template, I've done the following:

Then I add these attributes to the HomeController class:

[HandleError(ExceptionType = typeof(Exception), View = "Error")]
[HandleError(ExceptionType = typeof(CustomException), View = "CustomError")]

And this works fine - if a CustomException is thrown, the "CustomError" view is shown; if an Exception is thrown, the "Error" view is shown.

However, I thought the Order property on the HandleError attribute would make things more explicit. From the MSDN page:

The greater the integer value is, the lower the priority of the filter is.

From this, I would have thought that the following code would cause the "Error" view to be shown in all circumstances:

[HandleError(Order = 1, ExceptionType = typeof(Exception), View = "Error")]
[HandleError(Order = 2, ExceptionType = typeof(CustomException), View = "CustomError")]

But this is not the case; this causes the same behaviour as when the Order property was not specified. If I swap the Orders around, this causes the "Error" view to be shown, even if a CustomException was thrown.

Basically, the actual order priority seems to be exactly the opposite of the documentation. Am I doing something wrong or is this a bug?


Solution

  • Please follow this link:

    http://forums.asp.net/t/1699131.aspx/1?Filter+Execution+Order+Backwards

    order was changed to opposite