views:

36

answers:

2

I have an authentication filter that I want to put on all my actions in a given controller.

Is it possible to add a filter at the controller level?

+1  A: 

Yes, it's literally as simple as putting the ActionFilter attribute at the class level instead of the action level.

jamesaharvey
+1  A: 

Yes. It is then applied to all actions automatically.

[MyFilter]
public class MyController : Controller {

  // automatically has MyFilter logic attached to it
  public ViewResult MyAction() {
  }

}
gWiz