The entity type IdentityUser is not part of the model for the current context in ASP.NET Identity

徘徊边缘 提交于 2019-12-11 04:37:49

问题


I want to check if there is a user with particular username and password in ASP.NET Identity. I tried and that is my code:

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

However, something goes wrong and that is the error:

The entity type IdentityUser is not part of the model for the current context.

Would you tell me a solution?


回答1:


If you are using default MVC project you have to use ApplicationUser model instead of IdentityUser and update your code as follow:

  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);
    }


来源:https://stackoverflow.com/questions/40249076/the-entity-type-identityuser-is-not-part-of-the-model-for-the-current-context-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!