Beispiel #1
0
        /// <summary>
        /// Get HttpCookieValue
        /// </summary>
        /// <param name="alias"></param>
        /// <returns></returns>
        public HttpCookieValue <T> Get <T>(Enum alias) where T : IConvertible
        {
            HttpCookieValue <T> cookieValue = new HttpCookieValue <T>();

            if (_cookieSettings.ContainsKey(alias))
            {
                HttpCookieSetting setting = _cookieSettings[alias];

                HttpCookie cookie = Get(setting.Name);
                if (cookie != null)
                {
                    if (cookie.HasKeys)
                    {
                        cookieValue.ValueCollection.Deserialize(cookie.Value);
                    }
                    else
                    {
                        cookieValue.Value = Converter.Convert <T>(Decode(cookie.Value));
                    }
                }

                return(cookieValue);
            }

            return(cookieValue);
        }
Beispiel #2
0
 /// <summary>
 /// Set cookie
 /// </summary>
 /// <param name="alias"></param>
 /// <param name="cookieValue"></param>
 /// <param name="expires">MinValue means use default expires date from configuration</param>
 public void Set(Enum alias, HttpCookieValue cookieValue, TimeSpan expires)
 {
     if (_cookieSettings.ContainsKey(alias))
     {
         HttpCookieSetting setting = _cookieSettings[alias];
         expires = expires == TimeSpan.MinValue
                       ? (setting.AutoExpires ? TimeSpan.Zero : setting.Expires)
                       : expires;
         if (cookieValue.HasKeys)
         {
             Set(
                 setting.Name,
                 cookieValue.ValueCollection,
                 setting.Domain,
                 setting.Path,
                 expires,
                 setting.Secure,
                 setting.HttpOnly);
         }
         else
         {
             Set(
                 setting.Name,
                 cookieValue.ToString(),
                 setting.Domain,
                 setting.Path,
                 expires,
                 setting.Secure,
                 setting.HttpOnly);
         }
     }
 }
Beispiel #3
0
 public void ClearFix(Enum alias)
 {
     if (_cookieSettings.ContainsKey(alias))
     {
         HttpCookieSetting setting = _cookieSettings[alias];
         Clear(setting.Name, string.Empty);
     }
 }