private ActionResult CreateCookie(LoginModel model, string returnUrl, AccessRights roles) { //FormsAuthentication.SetAuthCookie(model.Username, false); var role = Enum.GetName(roles.GetType(), roles); var authTicket = new FormsAuthenticationTicket(1, model.Username, DateTime.Now, DateTime.Now.AddMinutes(30), false, role); string encryptedTicket = FormsAuthentication.Encrypt(authTicket); var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); HttpContext.Response.Cookies.Add(authCookie); var decodedUrl = ""; if (!string.IsNullOrEmpty(returnUrl)) { decodedUrl = Server.UrlDecode(returnUrl); } if (Url.IsLocalUrl(decodedUrl)) { return(Redirect(decodedUrl)); } return(RedirectToAction("Index", "Home")); }