Does anyone know if there is a way of using a value in Web.Config AppSettings section on an Authorize attribute for a controller in MVC3?
I am currently using something like this in web.config:
<add key="AdminRole" value="Admins"/>
, and then I tried pulling the into class and using the value on the Authorize attribute but .NET complains about the values not being constants, etc.
I just want to be able to use a value set in web.config to filter Authorization so that different deployments can use variations of role names based on their system configurations.
Any help would be appreciated, Thanks!
You would have to write your own AuthorizationAttribute class which at runtime reads the value from web.config. In .NET it is not possible to declare an attribute using runtime-dependent values.