How to get role-based users?

How will users from the customer role be removed from membership?

+5
source share
4 answers

Roles.GetUsersInRolereturns the string[]usernames in the role. If you really want objects MembershipUser, you can use:

var list = Roles.GetUsersInRole("roleName").Select(Membership.GetUser).ToList()

Of course, this is the intensity of the work, because it gets into the database once for each user.

If you are willing to give up provider independence, you can directly query the base database and connect to the database server to get all users in a specific role.

+13
source

To bind to ListBoxyou can use:

ListBox1.DataSource = System.Web.Security.Roles.GetUsersInRole("Role_Name");
ListBox1.DataBind();
+1
source

Use the RoleProvider class http://msdn.microsoft.com/en-us/library/system.web.security.roleprovider.aspx

has a FindUsersInRole method

0
source

All Articles