Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to authorize a set of controllers without placing the annotation on each one?

I have sets of controllers which are each used for each authorization type. For example, a class A authorization will have a set of controllers each which require class A authorization. Is there a way to place one [Authorize(Role="Class A")] attribute somewhere which will apply to each of those controllers without having to decorate each controller with the same attribute?

like image 858
Travis J Avatar asked Mar 22 '12 21:03

Travis J


1 Answers

You can initialize those controllers derived from your base controller. namely put your attribute on a controller base class and to ensure that each controller within derived from base class.

[Authorize(Role="Class A")]
public class CustomBaseController : Controller{}

public class AController: CustomBaseController{}

public class BController: CustomBaseController{}
like image 111
gandil Avatar answered Sep 30 '22 03:09

gandil