显示aspnet identity中的所有用户

Display all users in aspnet identity

这是我的 applicationDbContext class:

   public class ApplicationDbContext : IdentityDbContext<ApplicationUser, CustomRole,
int, CustomUserLogin, CustomUserRole, CustomUserClaim>

这是我的控制器操作方法,用于检索所有用户及其用户名:

   public JsonResult GetUsers()
    {
        var ret = (from user in db.Users
                   orderby user.Id
                   select new
                   {
                       UserName = user.UserName,
                   }).AsEnumerable();
        return Json(ret, JsonRequestBehavior.AllowGet);
    }

现在,我正在 运行 执行 problem.Whenever,我遇到了这个问题----不支持每种类型的多个对象集。对象集 'ApplicationUsers' 和 'Users' 都可以包含类型 'App.Models.ApplicationUser'.

的实例

我看到这个所以提问How to obtain a list of Users from ASP.NET Identity?。解决此问题的最简单方法是什么 error.Should 我遵循上述问题中给出的解决方案。我已经将我的用户 ID 属性 从字符串自定义为整数。

我猜你已经将它添加到你的 ApplicationDbContext 中:

public DbSet<ApplicationUser> ApplicationUsers { get; set; } 

虽然通过继承,您已经在 IdentityDbContext 中拥有它:

public IDbSet<ApplicationUser> Users { get; set; }

只需删除 ApplicationUsers 即可