Partial controller with various attributes in ASP.NET MVC

Suppose I have a controller that has routes to roles and other routers for other roles. I want the code to be cleaner by dividing these routes into partial classes. I know I can do it.

But I would like to know if I can do this:

[Authorize(Roles = "Admin")]
[MyLogger]
public partial class TheController{
     // Admin routes
}

and

[Authorize(Roles = "OtherRole")]
public partial class TheController{
     // Other routes that require auth
}

and

[AllowAnonymous]
public partial class TheController{
     // public routes
}

and the routes within each partial class receive only the attributes of that partial class.

Is it possible?

+4
source share
1 answer

TheController . , , - , .

0

Source: https://habr.com/ru/post/1684523/


All Articles