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("", "The user name or password provided is incorrect."); return View(model); }
public void Login(LoginModel model) { var dictionary = new Dictionary<string, object>(); dictionary.Add("username", model.UserName); dictionary.Add("password", ""); dictionary.Add("RememberMe", model.RememberMe); if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) { dictionary.Add("isError", false); } else { dictionary.Add("isError", "Invalid credentials."); } Response.Write(serializer.Serialize(dictionary)); Response.End(); }