Asked by:
ASP. NET MVC Identity List Users and Related Roles

Question
-
User-1089502229 posted
Hi,
I am new at development world.
I use ASP.NET Identity 2.0
public UsersAdminController(ApplicationUserManager userManager, ApplicationRoleManager roleManager) { UserManager = userManager; RoleManager = roleManager; } private ApplicationUserManager _userManager; public ApplicationUserManager UserManager { get { return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); } private set { _userManager = value; } } private ApplicationRoleManager _roleManager; public ApplicationRoleManager RoleManager { get { return _roleManager ?? HttpContext.GetOwinContext().Get<ApplicationRoleManager>(); } private set { _roleManager = value; } }
I want to list of users and user's roles together on Index page of Users.
// // GET: /Users/ public async Task<ActionResult> Index() { var user = await UserManager.Users.ToListAsync(); return View(user); }
I use ToList method but when i want to get user's roles, GetRoles method wants userId, but i don't get user Id,
Can anybody help to me?
Wednesday, December 23, 2015 12:37 PM
All replies
-
User-2057865890 posted
Hi,noreply
You could refer to the following links.
Code! MVC 5 App with Facebook, Twitter, LinkedIn and Google OAuth2 Sign-on
This tutorial shows you how to build an ASP.NET MVC 5 web application that enables users to log in using OAuth 2.0 with credentials from an external authentication provider, such as Facebook, Twitter, LinkedIn, Microsoft, or Google. For simplicity, this tutorial focuses on working with credentials from Facebook and Google.
Create a secure ASP.NET MVC 5 web app with log in, email confirmation and password reset
This tutorial shows you how to build an ASP.NET MVC 5 web app with email confirmation and password reset using the ASP.NET Identity membership system. You can download the completed application here.
Best regards,
Chris Zhao
Thursday, December 31, 2015 9:57 AM -
User-261648213 posted
Chris Zhao: Wow, I have to admin that is one of the most useless replies I have ever come across on an open forum without it actually being completely 100% off-topic. Congratulations. You just wasted the time of everyone looking for an answer.
FYI, I am also looking for an answer to OP’s question, and your reply provided ZERO assistance.
Saturday, February 6, 2016 5:59 AM -
User-261648213 posted
NoReply: Also looking for the same answer, I suspect the only way to do this is to ignore the entire controller and create a new one based off of ApplicationUser. Be careful, however -- I already tried this and nearly hosed by entire site with an auto-generated entry in IdentityModels.cs. In the end (I have not yet done this), you may have to replace ApplicationUser with User before you can successfully scaffold out that controller (if you create a controller and views based off of ApplicationUser, you will have both User and ApplicationUser responding to authentication and rights requests, which will kill your ability to log in or do anything while logged in).
Saturday, February 6, 2016 6:04 AM