ASP.NET MVC3 ActionFilterAttribute Priority/Selection - Bizarre?

If you set AllowMultiple = false and have the same action filter on both the controller and the action the one on the controller is never executed. If you set AllowMultiple=true it is the filter on the controller that gets executed first assuming same order The thing that changed in ASP. NET MVC 3 is the following: In previous versions of ASP.NET MVC, action filters are create per request except in a few cases.

This behavior was never a guaranteed behavior but merely an implementation detail and the contract for filters was to consider them stateless. In ASP.NET MVC 3, filters are cached more aggressively. Therefore, any custom action filters which improperly store instance state might be broken So to ensure that you are properly testing this: AttributeUsage(AttributeTargets.

All, AllowMultiple = true) public class MyActionFilterAttribute : ActionFilterAttribute { public string Name { get; set; } public override void OnActionExecuting(ActionExecutingContext filterContext) { Put a breakpoint here and inspect the value of the Name property ====> var name = Name; base. OnActionExecuting(filterContext); } }.

If you set AllowMultiple = false and have the same action filter on both the controller and the action the one on the controller is never executed. If you set AllowMultiple=true it is the filter on the controller that gets executed first assuming same order. The thing that changed in ASP.NET MVC 3 is the following: In previous versions of ASP.

NET MVC, action filters are create per request except in a few cases. This behavior was never a guaranteed behavior but merely an implementation detail and the contract for filters was to consider them stateless.In ASP. NET MVC 3, filters are cached more aggressively.

Therefore, any custom action filters which improperly store instance state might be broken.So to ensure that you are properly testing this: AttributeUsage(AttributeTargets. All, AllowMultiple = true) public class MyActionFilterAttribute : ActionFilterAttribute { public string Name { get; set; } public override void OnActionExecuting(ActionExecutingContext filterContext) { Put a breakpoint here and inspect the value of the Name property ====> var name = Name; base. OnActionExecuting(filterContext); } }.

Thanks Darin, but I'm seeing a different result than what you state. I'm setting AllowMultiple = false. If on the attribute of the Controller, I set Order = 1 and on the action with the same attribute, I don't set Order, then the attribute on the Controller is executed.

I'm checking this by doing System.Diagnostics.Debug. WriteLine(Name) in the OnActionExecuting override of the Attribute. Can you please try running your example with a higher Order value on the attribute of the Controller and confirm that the attribute on your Controller is indeed never run?Thanks.

– JohnnyO Mar 19 at 16:44.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions