Change role permissions in ASP.NET MVC

I am working on an ASP.NET MVC 5 web application. I am using

[Authorize(Roles="administrator")] public class MyController:Controller{}

Is there a way to dynamically add new authorized roles for the controller? For example, retrieve this information from a database or something similar so that it looks like this

[Authorize(Roles=db.MyControllerRoles)] public class MyController:Controller{}

+4
source share
1 answer

This role configuration is static. However, nothing prevents you from writing your own authorization filter, where you can do whatever you want. You need to implement an interface IAuthorizationFilter.

I have done such things in several projects and it works great.

+5
source

All Articles