Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net Identity Check for multiple roles to get access

Is it somehow possible to get asp.net identity to require membership of 2 roles before granting access?

I have 2 layers of rights in my system. First a company type that grants access to certain features, and secondly one that restricts the specific method and usage rights.

CompanyType= Host,Expert,Manufacturer,Supplier,Consultant
Accesslevel= Admin,ReadOnly,ReadWrite

i want to be able to do something like this:

[Authorize(Roles = "Expert && ReadWrite || ReadOnly")]

The goal is to have one way of handling both instead of having these roles:

HostAdmin, HostReadOnly, HostReadWrite, ExpertAdmin ....

Thanks for your time.

like image 928
Jakob Hviid PhD Avatar asked Dec 16 '22 00:12

Jakob Hviid PhD


1 Answers

Yes you can require more than one role, you just add more authorize attributes:

[Authorize(Roles="members")]
[Authorize(Roles="admin")]

This will require the user to both have the members and admin role

For more details -> Allow multiple roles to access controller action

like image 76
Zaphod Avatar answered Jan 05 '23 11:01

Zaphod