Viewing user roles show the role id instead of the role name

后端 未结 2 581
独厮守ぢ
独厮守ぢ 2021-01-15 17:21

I\'m trying to configure role-based authorization in ASP.NET Identity. I want to make it so that Admin users can see a list of users and their roles (on the Index page) and

2条回答
  •  心在旅途
    2021-01-15 18:12

    using System.Linq;
    using System.Data;
    using System.Data.Entity;
    
            var db = new ApplicationDbContext();
            var Users = db.Users.Include(u => u.Roles);
    
            foreach (var item in Users)
            {
                string UserName = item.UserName;
                string Roles = string.Join(",", item.Roles.Select(r=>r.RoleId).ToList());
            }
    

提交回复
热议问题