Getting All Users and All Roles through asp.net Identity

后端 未结 4 1005
栀梦
栀梦 2020-12-18 21:34

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 applicati

4条回答
  •  既然无缘
    2020-12-18 22:15

    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();
    

    In ASP.NET Identity 2.0 (currently in Alpha), this functionality is exposed on the UserManager and RoleManager...

    userManager.Users.ToList();
    roleManager.Roles.ToList();
    

    In both versions, you would be interacting with the RoleManager and UserManager to create roles and assign roles to users.

提交回复
热议问题