【问题标题】:The entity type IdentityUser is not part of the model for the current context in ASP.NET Identity实体类型 IdentityUser 不是 ASP.NET Identity 中当前上下文模型的一部分
【发布时间】:2016-10-25 20:24:43
【问题描述】:

我想检查 ASP.NET Identity 中是否存在具有特定用户名和密码的用户。我试过了,这就是我的代码:

UserManager<IdentityUser> userManager = new UserManager<IdentityUser>(new UserStore<IdentityUser>(new ApplicationDbContext()));
var user = await userManager.FindAsync(userName, password);

但是,出了点问题,那就是错误:

实体类型 IdentityUser 不是当前模型的一部分 上下文。

你能告诉我一个解决方案吗?

【问题讨论】:

    标签: c# asp.net asp.net-identity


    【解决方案1】:

    如果您使用默认 MVC 项目,则必须使用 ApplicationUser 模型而不是 IdentityUser 并更新您的代码如下:

      public async Task<ViewResult> Index()
        {
            UserManager<ApplicationUser> userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
            var user = await userManager.FindAsync("UserName", "Password");
            return View(user);
        }
    

    【讨论】:

    • 我工作了,但现在我遇到了另一个问题。 FindAsync 函数没有响应
    猜你喜欢
    • 2014-11-30
    • 1970-01-01
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-31
    • 2017-06-01
    • 2019-03-16
    相关资源
    最近更新 更多