How to get all users in a specific role?
Asked Answered
P

2

7

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

Predicant answered 6/2, 2012 at 8:43 Comment(0)
F
5

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.

Furtado answered 6/2, 2012 at 8:50 Comment(1)
Thx. Is there a way to map each string to a MemberShipuser?Predicant
M
5

Roles are handled by the role provider not the membership provider (for separation of authorisation from authentication).

So

string[] RoleProvider.GetUsersInRole(roleName)

(msdn).

Magistery answered 6/2, 2012 at 8:47 Comment(2)
Thx. Is there a way to map each string to a MemberShipuser?Predicant
@Predicant use Membership.GetUser.Magistery
F
5

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.

Furtado answered 6/2, 2012 at 8:50 Comment(1)
Thx. Is there a way to map each string to a MemberShipuser?Predicant

© 2022 - 2024 — McMap. All rights reserved.