How could users in a "customer" role be retrieved from a MembershipUserCollection?
如何从MembershipUserCollection中检索“客户”角色的用户?
4 个解决方案
#1
14
Roles.GetUsersInRole
returns a string[]
of user names in a role. If you really want the MembershipUser
objects, you can use:
Roles.GetUsersInRole返回角色中用户名的字符串[]。如果您真的想要MembershipUser对象,可以使用:
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
1
Go through this http://msdn.microsoft.com/en-us/library/system.web.security.roleprovider.findusersinrole.aspx
浏览此http://msdn.microsoft.com/en-us/library/system.web.security.roleprovider.findusersinrole.aspx
#3
1
For binding to a ListBox
you can use:
要绑定到ListBox,您可以使用:
ListBox1.DataSource = System.Web.Security.Roles.GetUsersInRole("Role_Name");
ListBox1.DataBind();
#4
0
Use the RoleProvider class http://msdn.microsoft.com/en-us/library/system.web.security.roleprovider.aspx
使用RoleProvider类http://msdn.microsoft.com/en-us/library/system.web.security.roleprovider.aspx
it has a FindUsersInRole method
它有一个FindUsersInRole方法
#1
14
Roles.GetUsersInRole
returns a string[]
of user names in a role. If you really want the MembershipUser
objects, you can use:
Roles.GetUsersInRole返回角色中用户名的字符串[]。如果您真的想要MembershipUser对象,可以使用:
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
1
Go through this http://msdn.microsoft.com/en-us/library/system.web.security.roleprovider.findusersinrole.aspx
浏览此http://msdn.microsoft.com/en-us/library/system.web.security.roleprovider.findusersinrole.aspx
#3
1
For binding to a ListBox
you can use:
要绑定到ListBox,您可以使用:
ListBox1.DataSource = System.Web.Security.Roles.GetUsersInRole("Role_Name");
ListBox1.DataBind();
#4
0
Use the RoleProvider class http://msdn.microsoft.com/en-us/library/system.web.security.roleprovider.aspx
使用RoleProvider类http://msdn.microsoft.com/en-us/library/system.web.security.roleprovider.aspx
it has a FindUsersInRole method
它有一个FindUsersInRole方法