我正在尝试为用户管理管理页面提取所有Identity用户及其相关角色.我认为这相当容易,但显然不是.我尝试过以下解决方案:https://stackoverflow.com/a/43562544/5392786但到目前为止还没有解决.
这是我到目前为止:
ApplicationUser:
public class ApplicationUser : IdentityUser
{
public List<IdentityUserRole<string>> Roles { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
的DbContext
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
Run Code Online (Sandbox Code Playgroud)
启动标识代码
services.AddIdentity<ApplicationUser, IdentityRole>(options => options.Stores.MaxLengthForKeys = 128)
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
Run Code Online (Sandbox Code Playgroud)
我想要显示列表的Razor Page:
public class IndexModel : PageModel
{
private readonly UserManager<ApplicationUser> userManager;
public IndexModel(UserManager<ApplicationUser> userManager)
{
this.userManager = userManager;
}
public IEnumerable<ApplicationUser> Users { get; set; }
public void OnGetAsync()
{
this.Users = userManager.Users.Include(u => …Run Code Online (Sandbox Code Playgroud) c# mysql entity-framework-core asp.net-core asp.net-core-identity