通过获取身份asp.net所有用户和角色 [英] Getting All Users and All Roles through asp.net Identity
问题描述
我有一个新的项目,我在2013年VS创建我使用的识别系统,我很困惑,如何让所有用户的列表,应用程序和所有角色的诠释,他的应用程序。我试图创建一些管理页面,所以我可以添加新角色,添加角色分配给用户,看看谁所有已登录或锁定。
I have a new project i created in VS 2013. I am using the identity system and i'm confused how to get a list of all users to the application and all roles int he application. I am trying to create some admin pages so i can add new roles, add roles to users, see who all is logged in or locked.
有人知道如何做到这一点?
Anybody know how to do this?
推荐答案
在ASP.NET 1.0的身份,你就必须从自身的DbContext得到这个...
In ASP.NET Identity 1.0, you'll have to get this from the DbContext itself...
var context = new ApplicationDbContext();
var allUsers = context.Users.ToList();
var allRoles = context.Roles.ToList();
在ASP.NET 2.0身份(目前在阿尔法),此功能被暴露在的UserManager
和 RoleManager
...
In ASP.NET Identity 2.0 (currently in Alpha), this functionality is exposed on the UserManager
and RoleManager
...
userManager.Users.ToList();
roleManager.Roles.ToList();
在两个版本中,你将与可交互的 RoleManager
和的UserManager
以创建角色和向用户分配角色
In both versions, you would be interacting with the RoleManager
and UserManager
to create roles and assign roles to users.
这篇关于通过获取身份asp.net所有用户和角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!