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?
it gives you the AspNetUserInRoles which stores UserId and RoleId. Instead you could try UserManger 's GetRoles method which will return you List<string> of roles user is assigned. But as you mentioned it will be only one role hence you can take first value from the result of GetRoles method.
Show activity on this post. var user = await _userManager. FindByIdAsync(UserId); var roles = await _userManager. GetRolesAsync(user); return OK(new { User = user, Roles = roles });
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With