/// <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)]); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }