public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl)) { if (User.IsInRole("Admin")) { return RedirectToAction("Index", "Admin"); } return Redirect(returnUrl); } else { if (User.IsInRole("Admin")) { return RedirectToAction("Index", "Admin"); } return RedirectToAction("Index", "Home"); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult JsonLogin(LoginModel model, string returnUrl) { if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (User.IsInRole("Admin")) { return RedirectToAction(controllerName: "Admin", actionName: "Index"); } return Json(new { success = true, redirect = returnUrl }); } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed return Json(new { errors = GetErrorsFromModelState() }); }