2

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.

Brando Zhang
  • 22,586
  • 6
  • 37
  • 65
Masoud
  • 21
  • 1
  • Does this answer your question? [Allow multiple roles to access controller action](https://stackoverflow.com/questions/700166/allow-multiple-roles-to-access-controller-action) – Kevin Mar 14 '22 at 10:04

1 Answers1

-1

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()
{
    ...
}
Brando Zhang
  • 22,586
  • 6
  • 37
  • 65
  • 1
    Stacking attributes will result in an AND condition where the policy must be true and the user must have the roles as well. – Jeff Barnard Apr 08 '22 at 20:12