One of the breaking changes in ASP.NET MVC 3 (and upwards) is that action filters, once instantiated, are cached and re-used on subsequent requests. Here is the relevant excerpt from the official [ASP.NET MVC 3 release notes][aspnetmvc-relnotes]:
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.
Essentially, if you are dealing with legacy code, that has poorly implemented custom action filters, you may end up with unexpected behavior once you migrate to a newer ASP.NET MVC release.
So, what is one to do?
Well, apparently, the default filter provider (FilterAttributeFilterProvider
) can be coerced into not caching instances of action filters. As it happens, its construct