public ActionResult New(LogOnModel model, string returnUrl) { if (ModelState.IsValid == false) { return View(model); } var valid = false; using (var context = new PrincipalContext(Context)) { valid = context.ValidateCredentials(model.UserName, model.Password, ContextOptions); } if (valid == false) { ModelState.AddModelError("", "The user name or password provided is incorrect"); return View(model); } FormsAuthentication.SetAuthCookie(model.UserName,model.RememberMe); if (Url.IsLocalUrl(returnUrl)) { return Redirect(returnUrl); } return RedirectToAction("Index", "Home"); }
public JsonResult JsonLogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); 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() }); }