Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • if the type of the exception is CustomException, use the "CustomError" view.
  • otherwise, use the default "Error" view.

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

  • Removed the HandleErrorAttribute from the global filters.
  • Turned Custom Errors on in the 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?

like image 897
Graham Clark Avatar asked Oct 11 '22 09:10

Graham Clark


1 Answers

Please follow this link:

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

order was changed to opposite

like image 155
objectbox Avatar answered Oct 20 '22 13:10

objectbox