hello experts
i am using below code for login and i get the error below plz help
"The entity type ApplicationUser is not part of the model for the current context."
public async Task Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View();
}
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, change to shouldLockout: true
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe,shouldLockout:false);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
//case SignInStatus.LockedOut:
// return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
}
}

Rijwan AnsariRank #82 · 24.2K reputationPosted Mar 23, 2021, 9:20 AM EDT
LaxmikantRank #5,709 · 289 reputationPosted Oct 21, 2015, 4:10 AM EDT
: base("MyContext")
{
}
Mukesh KumarRank #119 · 18.2K reputationPosted Oct 21, 2015, 4:43 AM EDT
The problem is that you're trying to add a User you added to one DbContext to a ApplicationUser you add to a different DbContext (created by the SignInManager).
Instead, you should do this as a single operation. Just do this:
var dbUser = new User { Firstname = model.FirstName, Lastname = model.LastName, Email = model.UserName }; var appUser = new ApplicationUser(model.UserName); appUser.UserInfo = dbUser; try { var result = await UserManager.CreateAsync(appUser, model.Password); } catch (Exception e) { // show error or whatever }