Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Authorize attribute using a constant expression

Tags:

c#

asp.net-mvc

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?

like image 944
Coppermill Avatar asked Nov 15 '22 15:11

Coppermill


1 Answers

  • SO - C# Dynamic Attribute Arguments
  • SO - use a global setting as an attribute argument
like image 135
eu-ge-ne Avatar answered Dec 19 '22 03:12

eu-ge-ne