In
[CustomAuthorize(Roles="Editor, Admin, Manager")]
- How can I use a variable / array of roles in static string
Roles="Editor, Admin, Manager"
? - How can I put a string variable or even n
list<string>
of CSV into the roles?
How to get rolesList into roles for customAttribute
List<string> rolesList = new List<string>();
rolesList.add("Editor").add("Admin").add("Manager");
//...
// now get that list
[CustomAuthorize(Roles= `"` + string.Join<string>(",", rolesList) + `"` )]
The short answer is, no. You can't. Attributes are static metadata compiled into your application, and thus cannot be updated at runtime.
The longer answer is that if you really need this functionality, you'll have to implement your own Authorize attribute.