Coppermill Coppermill - 4 months ago 23
C# Question

Authorize attribute using a constant expression

I am trying to set the Authorize for my controllers can do the following:

[Authorize(Roles = "Approver")]

How ever the names of the roles are held in the database, and therefore I would like to try and do the following:

[Authorize(Roles = Settings.Instance.RoleEmployee)]

but I get the following error:

An attribute argument must be a constant expression, typeof expression
or array creation expression of an attribute parameter type

Any way around this?