Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all users in a specific role?

How do i get all users from a specific role?

var users = Membership.GetAllUsers();

gets all users in all roles.

it returns a list of MembershipUser, but there is no role property.

Thanks

like image 624
Kenci Avatar asked Feb 06 '12 08:02

Kenci


1 Answers

You need to use the Roles class defined in System.Web.Security. It has a Roles.GetUsersInRole method.

Here is the documentation.

If you want to map the returned username to a MembershipUser you can use Membership.GetUser(string username) method on each of the returned values.

like image 100
Wouter de Kort Avatar answered Oct 05 '22 02:10

Wouter de Kort