Reputation: 117
I am working on 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 database or something similar, so it be like the following
[Authorize(Roles=db.MyControllerRoles)]
public class MyController:Controller{}
Upvotes: 4
Views: 1128
Reputation: 7254
This role configuration is static. However there is nothing preventing you from writing your own authorization filter where you can do whatever you want. You need to implement interface IAuthorizationFilter
.
I have done things like this in several projects and it's working fine.
Upvotes: 5