To authorize a controller for a specific role, the following attribute is required in the controller class:
[Authorize(Roles = "SampleRole")]
This requires the role name to be hardcoded on the controller and does not seem to be a flexible solution. My question is that you can specify a value for this role in the web.config file and use this key in the controller?
<appSettings> <add key="SampleRoleKey" value="SampleRole" /> ... </appSettings>
And in the controller
[Authorize(Roles = "SampleRoleKey")]
Another question: can we use a strongly typed role to authorize the controller?
source share