I am trying to make a login for a web app. The database was already existing so i used the instructions here to customize the table upon which the login would be performed. There were an error or two that i managed to fix(?) and now i am stuck in this and i really cant understand where it comes from. My context is this
public class ApplicationDbContext : IdentityDbContext<TblAdmin>
{
public ApplicationDbContext()
: base("TelecomConnection", throwIfV1Schema: false)
{
Database.SetInitializer<ApplicationDbContext>(null);
}
public DbSet<TblAdmin> TblAdmins { get; set; }
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<TblAdmin>().ToTable("tblAdmins");
}
}
The most relevant question is this which doesn't help me. The point when the problem occurs is when the user is providing the credentials for login and at that moment the compiler is stopping in this line
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe,shouldLockout:false);
the whole method in which this exists, is this:
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
// 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:
ModelState.AddModelError("", "Wrong Password.");
return View(model);
default:
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
}
}
I tried and searched the whole project and couldn't even find the world "Users". Anyone can tell me how to fix this?
IdentityDbContext<TUser>
already implements a DbSet
for TUser
:
public IDbSet<TUser> Users { get; set; }
Since TUser
here is TblAdmin
(IdentityDbContext<TblAdmin>
), when you add the following:
public DbSet<TblAdmin> TblAdmins { get; set; }
TblAdmin
is now tracked by two DbSet
s.