Link to home
Start Free TrialLog in
Avatar of Webbo_1980
Webbo_1980

asked on

How can i call Membership.GetAllUsers but only get users within a specified role

How can i call Membership.GetAllUsers but only get users within a specified role.

I'm aware of Roles.GetUsersInRole("Comgem") however this doesnt return the membersip columns i'm looking for.

Is this possible, while maintaining the same results set returned by GetAllusers?

Thanks
Avatar of Snarf0001
Snarf0001
Flag of Canada image

No single step way to do it:
The MembershipUser itself has no knowledge of what roles a user belongs to, that has to be queried from the RoleProvider as you've shown.

But, if you can use linq, a pretty easy to query the objects to get what you're after:
var members = from m in Membership.GetAllUsers().OfType<MembershipUser>()
                join u in Roles.GetUsersInRole("Comgem") on m.UserName equals u
                select m;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Snarf0001
Snarf0001
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial