public ActionResult LogonForm() { LogOnModel model = new LogOnModel(); return PartialView("_LogonForm", model); }
public ActionResult LogOn(LogOnModel model) { var data = new object(); try { if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(model.ReturnURL) && model.ReturnURL.Length > 1 && model.ReturnURL.StartsWith("/") && !model.ReturnURL.StartsWith("//") && !model.ReturnURL.StartsWith("/\\")) { return Redirect(model.ReturnURL); } else { data = new { success = true }; //return RedirectToAction("Index", "Home"); } } else { data = new { success = false, message = "The user name or password provided is incorrect." }; } } else { data = new { success = false, message = "Please correct any form errors and try again." }; } } catch (Exception ex) { data = new { success = false, message = ex.InnerException }; } // If we got this far, something failed, redisplay form return Json(data); }