public static void AuthenticateUser(string userName, int userId, string firstName, bool createPersistenctCookie)
        {
            try
            {
                var userData = new WarehouseManagementUserData()
                {
                    UserId = userId,
                    UserName = userName,
                    FirstName = firstName
                };

                var userDataString = WarehouseManagementUserData.Serialize(userData);
                var authCookie = FormsAuthentication.GetAuthCookie(userName, createPersistenctCookie);

                var ticket = FormsAuthentication.Decrypt(authCookie.Value);
                var extendedTicket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, userDataString);

                authCookie.Value = FormsAuthentication.Encrypt(extendedTicket);

                HttpContext.Current.Response.Cookies.Add(authCookie);
            }
            catch (Exception e)
            {
                throw new ProviderException(string.Format("Failed to authenticate user {0}.", userName), e);
            }
        }
 public OncologyNutritionUserIdentity(FormsAuthenticationTicket ticket, string userName)
     : base(userName)
 {
     WarehouseManagementUserData desiarializedUserData = WarehouseManagementUserData.Deserialize(ticket.UserData);
     if (desiarializedUserData != null)
     {
         userData = desiarializedUserData;
     }
 }
        public static string Serialize(WarehouseManagementUserData userData)
        {
            var serializer = new DataContractJsonSerializer(typeof(WarehouseManagementUserData));

            using (var stream = new MemoryStream())
            {
                serializer.WriteObject(stream, userData);

                return Encoding.UTF8.GetString(stream.ToArray());
            }
        }