public static void SetCookie(string userName, bool persistent, UserData data) { var encodedUserData = CookieHelper.EncodeUserData(data); var ticket = new FormsAuthenticationTicket( 1, userName, DateTime.Now, DateTime.Now.Add(FormsAuthentication.Timeout), persistent, encodedUserData, FormsAuthentication.FormsCookiePath ); var encryptedTicket = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); HttpContext.Current.Response.SetCookie(cookie); }