public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { System.Web.Security.FormsAuthentication.SignOut(); //var user = await UserManager.FindAsync(model.UserName, model.Password); CaterpillarContext db = new CaterpillarContext(); List <User> foundUsers = db.Users.Where(u => u.UserName == model.UserName && u.Password == model.Password).ToList(); if (foundUsers.Count > 0) { System.Web.Security.FormsAuthentication.SetAuthCookie(foundUsers[0].UserName, true); System.Web.Security.FormsAuthentication.RedirectToLoginPage(); } else { ModelState.AddModelError("", "Invalid username or password."); } } // If we got this far, something failed, redisplay form return(View(model)); }