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?
Building on what Anthony Chu said, in Identity 2.x, you can get the roles using a custom helper method:
System.Web.Security Roles class also allows obtaining the list of roles.
List<String> roles = System.Web.Security.Roles.GetAllRoles();
In ASP.NET Identity 1.0, you'll have to get this from the DbContext itself...
In ASP.NET Identity 2.0 (currently in Alpha), this functionality is exposed on the
UserManager
andRoleManager
...In both versions, you would be interacting with the
RoleManager
andUserManager
to create roles and assign roles to users.Building on Anthony Chu and Alex.
Creating two helper classes...
Two methods to get the roles and users.
Two examples of Methods using GetRoles() and GetUsers() to populat a dropdown.
usage example:
thx to Anthony and Alex for helping me understand these Identity classes.