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