Since it doesn't appear to be supported natively, what's the recommended way of implementing global filters on a per-area basis?
Area-global filters in MVC 3
Asked Answered
You could use a custom IFilterProvider.
That should do it! Good thinking –
Emilie
The reason it's not supported natively is because we want to discourage developers from doing it. Areas are not associated with controllers; they're associated with routes. We wanted to discourage developers from trying to apply authorization or other security-sensitive filters to areas since they can be bypassed.
See How can we set authorization for a whole area in ASP.NET MVC? for more information.
For an MVC 4 update, see blogs.msdn.com/b/rickandy/archive/2012/03/23/… –
Boorman
"Areas are not associated with controllers" -- funny that I can see a controllers folder in each area. Controllers are always associated with an area: either the "root" area, or a custom area. So I disagree. A common example of areas is to create an "Admin" area - guess what filter you'd want to apply globally to just that area. –
Gonsalve
@Gonsalve Your assumption is incorrect. See also my answer to #2319657, which demonstrates that controllers don't belong to areas. –
Wimsatt
Thanks for explaining that: I now understand what you mean better, and withdraw my previous comment. It sounds like the controller factory is being too helpful in matching stuff up. –
Gonsalve
You could use a custom IFilterProvider.
That should do it! Good thinking –
Emilie
© 2022 - 2024 — McMap. All rights reserved.
ActionFilters
? – MyogenicActionFilters
are a specific implementation of the broaderIFilter
– Emilie