如何让用户不在角色中,
是否有任何相当有效的方法来获取不属于特定角色的用户列表?
我能看到的唯一方法是
从数据库获取所有用户并执行代码签入
直接进入数据库并回避角色提供者
Is there any reasonably efficient way to get a list of users who are not in a specific role?
The only methods I can see are
Get all the users from DB and do a check in code
Go directly to the db and sidestep the role provider
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以获取所有用户列表并提取列表中指定角色的用户:
You could just get the all user list and extract users in role specified from the list:
在 Alex 提供的代码中将 Select 更改为Where 将实际返回结果,而不仅仅是 true/false。
Changing the Select to Where in the code provided by Alex will actually return the results instead of just true/false.
另一种方法是使用 GetUsersNotInRole() 方法扩展 RoleProvider 并在那里查询数据库。您还可以将 RoleProvider.GetUsersInRole() 与 MembershipProvider.GetAllUsers() 结合起来并找出区别
Another way is to extend RoleProvider with the method GetUsersNotInRole() and query the DB there. You can also combine RoleProvider.GetUsersInRole() with MembershipProvider.GetAllUsers() and find the difference
我不认为绕过角色提供者直接查询数据库有什么问题。这样你一定会得到最好的表现。
I don't think that there is anything wrong with by-passing the role provider and querying the database directly. You will definitely get the best performance this way.
找到这个方法,希望这对其他人也有帮助。很容易。
Found this way, hope this helps others aswell. Very easy.