Exemplo n.º 1
0
        /// <summary>
        /// Get a particular value from the Hobbes cookie in the cookie collection
        /// </summary>
        /// <param name="cookies"></param>
        /// <param name="key"></param>
        /// <returns>return a specific key from the cookie</returns>
        public static string GetHobbesCookieValue(HttpCookieCollection cookies, string key)
        {
            HttpCookie retCookie = cookies[HttpUtility.HtmlEncode(HobbesCookieName)];

            retCookie = CookieExtensions.DecryptCookie(retCookie);
            //cookie values are decoded
            return(retCookie.Values[HttpUtility.HtmlEncode(key)]);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get value from a SCAMPS encrypted cookie
        /// </summary>
        /// <param name="cookie"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetCookieValue(HttpCookie cookie, string key)
        {
            string     retVal = null;
            HttpCookie temp   = CookieExtensions.DecryptCookie(cookie);

            retVal = temp.Values[key];
            return(retVal);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Update a cookie key value pair
        /// </summary>
        /// <param name="cookie"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns>new encrypted cookie with updated key,value pair</returns>
        public static HttpCookie SetCookieValue(HttpCookie cookie, string key, string value)
        {
            HttpCookie retCookie = CookieExtensions.DecryptCookie(cookie);

            //Unencrypted cookie...
            //Now the values can be manipulated
            retCookie.Values[key] = value;
            retCookie             = CookieExtensions.EncryptCookie(retCookie);
            //Encrypted cookie
            retCookie.Expires = NewExpiresTime();
            return(retCookie);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Add subvalues to a cookie...creates new KV pair if nonexistant
        /// Adds additional values to key otherwise!
        /// </summary>
        /// <param name="cookie">Cookie to add kv pair to</param>
        /// <param name="key">key</param>
        /// <param name="value">concatentaed values (if more than one)</param>
        /// <returns>new encrypted cookie with added value </returns>
        public static HttpCookie AddTo(HttpCookie cookie, string key, string value)
        {
            HttpCookie retCookie = CookieExtensions.DecryptCookie(cookie);

            //Unencrypted cookie...
            //Now the values can be manipulated
            retCookie.Values.Add(key, value); //this can add duplicate and additional values to a key
            retCookie = CookieExtensions.EncryptCookie(retCookie);
            //Encrypted cookie
            retCookie.Expires = NewExpiresTime();
            return(retCookie);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Add a list of KV pairs to our cookie
        /// </summary>
        /// <param name="cookie"></param>
        /// <param name="valuesDict"></param>
        /// <returns></returns>
        public static HttpCookie AddTo(HttpCookie cookie, Dictionary <string, string> valuesDict)
        {
            HttpCookie retCookie = CookieExtensions.DecryptCookie(cookie);

            //Unencrypted cookie...
            //Now the values can be manipulated
            foreach (var item in valuesDict)
            {
                retCookie.Values.Add(item.Key, item.Value);
            }
            retCookie = CookieExtensions.EncryptCookie(retCookie);
            //Encrypted cookie
            retCookie.Expires = NewExpiresTime();
            return(retCookie);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Make an encrypted IRCDA cookie
        /// </summary>
        /// <param name="cookieName"></param>
        /// <param name="value">if provided, is the Value (or Values [0]of the cookie)</param>
        /// <returns>New Cookie, encrypted or null if no Cookie Name</returns>
        public static HttpCookie MakeCookie(string cookieName, string value = null)
        {
            HttpCookie retCookie = null;

            if (!string.IsNullOrEmpty(cookieName))
            {
                retCookie         = new HttpCookie(HttpUtility.HtmlEncode(cookieName));
                retCookie.Expires = CookieTools.NewExpiresTime();
                if (!string.IsNullOrEmpty(value))
                {
                    retCookie.Value = HttpUtility.HtmlEncode(value);
                }
                retCookie = CookieExtensions.EncryptCookie(retCookie);
            }
            return(retCookie);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Return all cookie values as a dictionary
        /// </summary>
        /// <param name="cookie"></param>
        /// <returns>Dictionary of cookie key value pairs</returns>
        public static Dictionary <string, string> GetCookieValues(HttpCookie cookie)
        {
            Dictionary <string, string> retval = new Dictionary <string, string>();

            if (cookie != null)
            {
                cookie = CookieExtensions.DecryptCookie(cookie);
                //make dictionary with decoded values
                foreach (string key in cookie.Values)
                {
                    var val = cookie.Values[key];
                    if (!key.IsNullOrEmpty())
                    {
                        retval.Add(key, HttpUtility.HtmlDecode(val));
                    }
                }
            }
            return(retval);
        }