public void Append(string key, string value, CookieOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var issueCookie = CanTrack || options.IsEssential;

            ApplyPolicy(options);
            if (Options.OnAppendCookie != null)
            {
                var context = new AppendCookieContext(Context, options, key, value)
                {
                    IsConsentNeeded = IsConsentNeeded,
                    HasConsent      = HasConsent,
                    IssueCookie     = issueCookie,
                };
                Options.OnAppendCookie(context);

                key         = context.CookieName;
                value       = context.CookieValue;
                issueCookie = context.IssueCookie;
            }

            if (issueCookie)
            {
                Cookies.Append(key, value, options);
            }
        }
Exemple #2
0
 public void Append(string key, string value)
 {
     if (CheckPolicyRequired() || Options.OnAppendCookie != null)
     {
         Append(key, value, new CookieOptions());
     }
     else
     {
         Cookies.Append(key, value);
     }
 }
Exemple #3
0
        public void Append(string key, string value, CookieOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (ApplyAppendPolicy(ref key, ref value, options))
            {
                Cookies.Append(key, value, options);
            }
        }
            public void Append(string key, string value, CookieOptions options)
            {
                if (options == null)
                {
                    throw new ArgumentNullException(nameof(options));
                }

                ApplyPolicy(options);
                if (Policy.OnAppendCookie != null)
                {
                    var context = new AppendCookieContext(Context, options, key, value);
                    Policy.OnAppendCookie(context);
                    key   = context.CookieName;
                    value = context.CookieValue;
                }
                Cookies.Append(key, value, options);
            }
Exemple #5
0
        /// <summary>
        /// set the cookie
        /// </summary>
        /// <param name="key">key (unique indentifier)</param>
        /// <param name="value">value to store in cookie object</param>
        /// <param name="expireTime">expiration time</param>
        public void Set(string key, string value, int?expireTime)
        {
            CookieOptions option = new CookieOptions();

            if (expireTime.HasValue)
            {
                option.Expires = DateTime.Now.AddMinutes(expireTime.Value);
            }
            else
            {
                option.Expires = DateTime.Now.AddMinutes(20);
            }

            option.HttpOnly = true;
            value           = HttpSessionDataServices.encodeData(value);
            Cookies.Append(key, value, option);
        }
Exemple #6
0
        public void AppendCookie(Cookie cookie)
        {
            var options = new CookieOptions()
            {
                Domain   = cookie.Domain,
                Secure   = cookie.Secure,
                HttpOnly = cookie.HttpOnly,
            };

            if (!string.IsNullOrEmpty(cookie.Path))
            {
                options.Path = cookie.Path;
            }
            if (cookie.Expires != DateTime.MinValue)
            {
                options.Expires = cookie.Expires;
            }

            Cookies.Append(cookie.Name, cookie.Value, options);
        }