[英]ASP.NET Get Only Users with Roles using ActiveDirectoryMembershipProvider and SqlRoleProvider
I've inherited a site that uses an ActiveDirectoryMembershipProvider
for authentication and a SqlRoleProvider
for authorization. 我继承了一个使用ActiveDirectoryMembershipProvider
进行身份验证和使用SqlRoleProvider
进行授权的SqlRoleProvider
。 The authentication is going against our company's LDAP server, so there's a couple hundred users. 身份验证针对我们公司的LDAP服务器,因此有几百个用户。 However, the site I'm creating will only use about 60 or 70 of those users. 但是,我正在创建的网站将仅使用其中的60或70个用户。
Is there a way to easily get just the users of my site (ie the Users with Roles in my SqlRoleProvider
)? 有没有一种方法可以轻松地仅获取我网站的用户(即SqlRoleProvider
具有角色的用户)? Or do I have to get all (couple hundred) Users, then loop through and see if their Roles match any of the Roles in my site? 还是我必须获得所有(几百个)用户,然后遍历并查看其角色是否与我的网站中的任何角色匹配?
If anybody is curious, I ended up using a nested foreach
; 如果有人好奇,我最终会使用嵌套的foreach
; looping through all the roles in my site, then looping through Roles.GetUsersInRole(role)
and adding the user to a List<> (after first checking to make sure they weren't already in it). 遍历我站点中的所有角色,然后遍历Roles.GetUsersInRole(role)
并将用户添加到List <>(首先检查以确保他们不在其中)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.