How to add "Role Or Policy" to Authorize in .net Core

Viewed 67

Can i make Authorize Like this in .net Core API:

[Authorize(Roles = "SUPPORT") OR Policy = "SuperUser"]
public IActionResult MyMethod()
{
    ...
}

mean if user has "SUPPORT" role OR has "SuperUser" Police can access to MyMethod.

1 Answers

According to your description, I suggest you could put multiple Authorize attribute to achieve your requirement.

Like below:

[Authorize(Policy = "SuperUser")]
[Authorize(Roles = "SUPPORT")]
public IActionResult MyMethod()
{
    ...
}
Related