コード例 #1
0
        /// <summary>
        /// Gets the embedded data from authentication cookie.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T GetEmbeddedDataFromAuthenticationCookie <T>()
        {
            HttpContext currentContext = HttpContext.Current;
            IPrincipal  user           = currentContext.User;

            if (user != null && user.Identity.IsAuthenticated)
            {
                return(XmlSerializationHelper <T> .ConvertFromXml(FormsAuthentication.Decrypt(HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName].Value).UserData));
            }

            return(default(T));
        }