Exemplo n.º 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Set sub cookie
        /// </summary>
        /// <param name="alias"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="expires"></param>
        public void Set(Enum alias, string name, string value, TimeSpan expires)
        {
            HttpCookieValue cookieValue = new HttpCookieValue();

            cookieValue.ValueCollection.Add(name, value);
            Set(alias, cookieValue, expires);
        }
Exemplo n.º 3
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);
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Set cookie
        /// </summary>
        /// <param name="alias"></param>
        /// <param name="value"></param>
        /// <param name="expires"></param>
        public void Set(Enum alias, string value, TimeSpan expires)
        {
            HttpCookieValue cookieValue = new HttpCookieValue();

            cookieValue.Value = value;
            Set(alias, cookieValue, expires);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get sub cookie value
        /// </summary>
        /// <param name="alias"></param>
        /// <param name="name">Sub Cookie Name</param>
        /// <returns></returns>
        public T Get <T>(Enum alias, string name) where T : IConvertible
        {
            HttpCookieValue <T> cookieValue = Get <T>(alias);

            if (cookieValue != null)
            {
                if (cookieValue.ValueCollection.ContainsKey(name))
                {
                    return(cookieValue.ValueCollection.Get <T>(name));
                }
            }
            return(default(T));
        }