I want to assign Group name as an attribute for authorize filter.
It will take as below
[FilterConfig.AuthorizeAd(Group = "DirectoryName")] public ActionResult GetData() { }
Insted of hardcoding i tried by adding it as below
[FilterConfig.AuthorizeAd(Group = Constants.ActiveDirectoryName)]
Where Constants is class and created member as below:
public const string ActiveDirectoryName = "directoryName";
Now i want to aceess it from app.config, tried as below
[FilterConfig.AuthorizeAd(Group = ConfigurationManager.AppSettings["Directory_Name"].ToString()
It is throughing the error msg as "An attribute argument must be a constant expression"
How can i assign the data from config? Please suggest me.
You can't do that with attributes, they have to be constants as stated in the error message. If you wanted to get a value from the configuration file, you could do it by passing the key to the attribute, and then in the constructor get the value you want from the configurationmanager
public MyAttribute :Attribute
{
private string _config;
public MyAttribute(string configKey)
{
_config = ConfigurationManager.AppSettings[configKey];
...
}
}
HTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With