[Authorize] public ActionResult Home() { return View(); } public ActionResult Login() { return View(); } [HttpPost] public ActionResult Login(User_info ui,string returnUrl) { if (ModelState.IsValid) { using (CRM_DBEntities crm = new CRM_DBEntities()) { var details = crm.User_info.Where(a => a.Username.Equals(ui.Username) && a.Password.Equals(ui.Password)).FirstOrDefault(); if (details != null) { FormsAuthentication.SetAuthCookie(details.Username, false); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } else { return RedirectToAction("Home", "crm"); } //Session["Username"] = details.Email.ToString(); //return RedirectToAction("Home","crm"); } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); return View(); } } } return View(); } [Authorize] public ActionResult Logout() { FormsAuthentication.SignOut(); return RedirectToAction("Index","Home"); }
<system.web> <authentication mode="Forms"> <forms loginUrl="~/crm/Login" defaultUrl="~/" timeout="20" slidingExpiration="true"/> </authentication>
FormsAuthentication.SetAuthCookie(details.Username, false);
FormsAuthentication.SetAuthCookie(details.Username, true);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)