使用 Roles.GetUsersInRole 或其他方式查找不属于特定角色的所有用户
我需要使用不存在于特定角色中的用户列表填充一个数组并计算结果。
目前我使用此代码,但我无法获得“CMS-ADMINISTRATOR”角色之外的用户。
知道如何做到这一点并更好地编写计数部分吗?
string[] usersInRole;
usersInRole = Roles.GetUsersInRole("CMS-ADMINISTRATOR");
int c = usersInRole.Count();
I need populate an array with a list of Users that ARE NOT PRESENT in a specific Role and COUNT the result.
At the moment I use this code, but I am not able to get the Users outside "CMS-ADMINISTRATOR " role.
Any idea how to do it and better write the Count section?
string[] usersInRole;
usersInRole = Roles.GetUsersInRole("CMS-ADMINISTRATOR");
int c = usersInRole.Count();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您只需要不属于该角色的用户数,则可以从用户总数中减去该角色的用户数:
If you just need the number of users not in the role, you can subtract the number of users in the role from the total number of users:
请尝试一下,
adminusers.count
也可以返回到视图中
Please try,
adminusers.count
you can also return it to the view
不确定是否让用户脱离“CMS-ADMINISTRATOR”角色,但至少您可以更好地编写原始代码,如下所示:
Not sure about getting users outside the "CMS-ADMINISTRATOR" role, but at least you can write the original code better like this:
也许是这样的:
或者使用 Andy Mikula 建议的方法,如果您只需要计数,这会更简单。
Maybe this:
Or use what Andy Mikula suggests which is simpler if you just need the count.