public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) { return RedirectToLocal(returnUrl); } // 如果我们进行到这一步时某个地方出错,则重新显示表单 ModelState.AddModelError("", "提供的用户名或密码不正确。"); return View(model); }
public ActionResult Login(LoginModel model, string returnUrl) { try { if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) { if (!String.IsNullOrEmpty(returnUrl)) { return Redirect(returnUrl); } else { return Redirect("/Admin/Index"); } } ModelState.AddModelError("", "用户名或密码错误"); return View(model); } catch (HttpAntiForgeryException) { return View(); } }