6

Since it doesn't appear to be supported natively, what's the recommended way of implementing global filters on a per-area basis?

Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
Richard Szalay
  • 83,269
  • 19
  • 178
  • 237

2 Answers2

9

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.

Community
  • 1
  • 1
Levi
  • 32,628
  • 3
  • 87
  • 88
  • 1
    For an MVC 4 update, see http://blogs.msdn.com/b/rickandy/archive/2012/03/23/securing-your-asp-net-mvc-4-app-and-the-new-allowanonymous-attribute.aspx – RickAndMSFT Mar 23 '12 at 23:43
  • 4
    _"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. – Quango Jan 24 '13 at 14:26
  • 1
    @Quango Your assumption is incorrect. See also my answer to http://stackoverflow.com/questions/2319157/how-can-we-set-authorization-for-a-whole-area-in-asp-net-mvc/2320419#2320419, which demonstrates that controllers don't belong to areas. – Levi Jan 24 '13 at 20:50
  • 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. – Quango Jan 25 '13 at 08:14
2

You could use a custom IFilterProvider.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928