How to get users based on role?

陌路散爱 提交于 2019-12-06 00:58:46

问题


How could users in a "customer" role be retrieved from a MembershipUserCollection?


回答1:


Roles.GetUsersInRole returns a string[] of user names in a role. If you really want the MembershipUser objects, you can use:

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

Of course, this is performance intensive as it hits the database once for every user.

If you are willing to give up provider-independence, you can query the underlying database directly and perform a join on the database server to get all users in a specific role.




回答2:


Go through this http://msdn.microsoft.com/en-us/library/system.web.security.roleprovider.findusersinrole.aspx




回答3:


For binding to a ListBox you can use:

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



回答4:


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

it has a FindUsersInRole method



来源:https://stackoverflow.com/questions/4779264/how-to-get-users-based-on-role

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!