public ActionResult LogOff() { PIAuthenticationConfiguration config = PIAuthenticationConfiguration.Current; HttpCookie cookie = Request.Cookies[config.CookieName]; if (cookie != null) { cookie.Expires = DateTime.Now.AddYears(-1); Response.SetCookie(cookie); } //FormsAuthentication.SignOut(); return(RedirectToAction("Index", "Home")); }
public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { User user; if (userRepo.TryAuthenticate(model.UserName, model.Password, out user)) { if (!user.IsActivated) { ModelState.AddModelError("", "The user is not active."); return(View(model)); } if (user.IsSuspended) { ModelState.AddModelError("", "This user is suspended."); return(View(model)); } PIAuthenticationConfiguration config = PIAuthenticationConfiguration.Current; FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1 , user.Identity.Name , DateTime.Now , DateTime.Now.AddYears( config.CookieExpiration) , model.RememberMe , "" , "/" ); HttpCookie cookie = new HttpCookie(config.CookieName, FormsAuthentication.Encrypt(ticket)); Response.SetCookie(cookie); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return(Redirect(returnUrl)); } return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("", "The user name or password provided is incorrect."); } // If we got this far, something failed, redisplay form return(View(model)); }