Search code examples
c#asp.netasp.net-identity

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


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?


Solution

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