public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) { return RedirectToLocal(returnUrl); } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "Thông tin đăng nhập không hợp lệ!"); return View(model); }
public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) { Session["Username"] = model.UserName; var user = context.Accounts.FirstOrDefault(x => x.Username == model.UserName); if (user != null) { Session["Role"] = user.Role.Rolename; } return RedirectToLocal(returnUrl); } // If we got this far, something failed, redisplay form ModelState.AddModelError("","Tên tài khoản hoặc mật khẩu chưa đúng."); return View(model); }