public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) return View(model); var user = await UserManager.FindAsync(model.Email, model.Password); if (user != null) { await SignInAsync(user, model.RememberMe); using (var db = new ApplicationDbContext()) { var t = db.Users.First(a => a.Email == model.Email); if (t != null) { t.LastIn = DateTime.Now; db.Entry(t).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } db.Dispose(); } if (HttpRuntime.Cache["LoggedInUsers"] != null) //if the list exists, add this user to it { //get the list of logged in users from the cache var loggedInUsers = (List<string>)HttpRuntime.Cache["LoggedInUsers"]; //add this user to the list loggedInUsers.Add(model.Email); //add the list back into the cache HttpRuntime.Cache["LoggedInUsers"] = loggedInUsers; } else //the list does not exist so create it { //create a new list var loggedInUsers = new List<string> {model.Email}; //add this user to the list //add the list into the cache HttpRuntime.Cache["LoggedInUsers"] = loggedInUsers; } return RedirectToLocal(returnUrl); } ModelState.AddModelError("", "Недопустимое имя пользователя или пароль."); return View(model); }
public ActionResult Login(string returnUrl) { var t = new LoginViewModel(); ViewBag.ReturnUrl = returnUrl; return View(t); }