protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //let us take out the username now
                        var ticket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
                        if (ticket != null)
                        {
                            string username = ticket.Name;
                            //string roles = ticket.UserData;

                            var userData = MZHelperSerialize.Deserialize <UserDataDTO>(ticket.UserData);

                            var roles = userData.Roles;

                            //Let us set the Pricipal with our user specific details
                            e.User = new System.Security.Principal.GenericPrincipal(
                                new System.Security.Principal.GenericIdentity(username, "Forms"), roles.Split(';'));
                        }
                    }
                    catch
                    {
                        FormsAuthentication.SignOut();
                        //somehting went wrong
                    }
                }
            }
        }
        protected UserDataDTO GetUserDataInContext()
        {
            UserDataDTO result = null;

            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //let us take out the username now
                        var ticket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
                        if (ticket != null)
                        {
                            result = MZHelperSerialize.Deserialize <UserDataDTO>(ticket.UserData);
                            RegisterUserActive(DateTime.Now, result);
                        }
                    }
                    catch
                    {
                        FormsAuthentication.SignOut();
                    }
                }
            }

            return(result);
        }
 /// <summary>
 /// Deserializa um objeto
 /// </summary>
 /// <typeparam name="T">Tipo do OBjecto</typeparam>
 /// <param name="jsonObject">String Json do OBjeto</param>
 /// <returns>Objeto</returns>
 protected T Deserialize <T>(string jsonObject, CultureInfo culture = null) where T : class
 {
     if (culture == null)
     {
         culture = new CultureInfo("en-US");
     }
     return(MZHelperSerialize.Deserialize <T>(jsonObject, culture));
 }
 //}
 /// <summary>
 /// Retorna um objeto serializado em JSON
 /// </summary>
 /// <typeparam name="T">Tipo do Objeto a ser serializado</typeparam>
 /// <param name="obj">Objeto a ser serializado</param>
 /// <returns>String contendo o objeto</returns>
 protected string Serialize <T>(T obj, CultureInfo culture = null) where T : class
 {
     if (culture == null)
     {
         culture = new CultureInfo("en-US");
     }
     return(MZHelperSerialize.Serialize <T>(obj, culture));
 }