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:
CustomException
, use the "CustomError" view.Using the default MVC project template, I've done the following:
HandleErrorAttribute
from the global filters.web.config
.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?
Please follow this link:
http://forums.asp.net/t/1699131.aspx/1?Filter+Execution+Order+Backwards
order was changed to opposite
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With