public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { if (UserSvc.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home"); } } else { ModelState.AddModelError("", "用户名或密码不正确!"); } } return View(model); }
public ActionResult Init(LogOnModel model) { if (ModelState.IsValid) { bool isSuccess = UserSvc.InitUser(model.UserName, model.Password); if (!isSuccess) { ModelState.AddModelError("", "用户名或密码不正确!"); return View(model); } FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); return RedirectToAction("Index", "Home"); } return View(model); }