Contains several cookie related constants.
Exemple #1
0
 public static string GetCurrentToken(CookieKeys key)
 {
     if (HttpContext.Current.Request.Cookies[key.ToString()] != null)
     {
         string token = HttpContext.Current.Request.Cookies[key.ToString()].Value;
         return(token);
     }
     return(null);
 }
Exemple #2
0
        private void Set(CookieKeys key, string value)
        {
            HttpCookie cookie = new HttpCookie(key.ToString());

            cookie.Expires = DateTime.Now.AddMonths(1);
            cookie.Value   = value;

            HttpContext.Current.Response.SetCookie(cookie);
        }
Exemple #3
0
        public static bool CookieIsExist(CookieKeys key)
        {
            if (HttpContext.Current.Request.Cookies[key.ToString()] != null)
            {
                return(true);
            }

            return(false);
        }
Exemple #4
0
 public static void ExpireCookie(CookieKeys key, int timeMonthAmount)
 {
     HttpContext.Current.Session.Abandon();
     if (HttpContext.Current.Request.Cookies[key.ToString()] != null)
     {
         HttpCookie currentCookie = new HttpCookie(key.ToString());
         currentCookie.Expires = DateTime.Now.AddMonths(timeMonthAmount);
         HttpContext.Current.Response.Cookies.Add(currentCookie);
     }
 }
Exemple #5
0
        public static string GetCurrentUrl(CookieKeys key)
        {
            string url = "MyEvernoteHome/Index";

            if (HttpContext.Current.Request.Cookies[key.ToString()] != null)
            {
                url = HttpContext.Current.Request.Cookies[key.ToString()].Value;
            }

            return(url);
        }
Exemple #6
0
        public static User GetCurrentUser(CookieKeys key)
        {
            UserManager _usm = new UserManager();

            if (HttpContext.Current.Request.Cookies[key.ToString()] != null)
            {
                string token = HttpContext.Current.Request.Cookies[key.ToString()].Value;
                User   user  = _usm.Get(x => x.Token.ToString() == token);
                return(user);
            }
            return(null);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expireTime">expireTime of minutes</param>
        public static void Set(HttpContext context, CookieKeys key, string value, ExpireTimeMode?expireTimeMode = null, int?expireTime = null)
        {
            var cookieName = Keys[key];

            var option = new CookieOptions
            {
                HttpOnly = true, IsEssential = true, SameSite = SameSiteMode.Strict, Secure = false
            };

            if (expireTime.HasValue && expireTimeMode.HasValue)
            {
                option.Expires = expireTimeMode switch
                {
                    ExpireTimeMode.Day => DateTime.Now.AddDays(expireTime.Value),
                    ExpireTimeMode.Hour => DateTime.Now.AddHours(expireTime.Value),
                    ExpireTimeMode.Minute => DateTime.Now.AddMinutes(expireTime.Value),
                    _ => option.Expires
                };
            }

            context.Response.Cookies.Append(cookieName, value, option);
        }
        public static void Remove(HttpContext context, CookieKeys key)
        {
            var cookieName = Keys[key];

            context.Response.Cookies.Delete(cookieName);
        }
Exemple #9
0
        private string Get(CookieKeys key)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[key.ToString()];

            return(cookie == null ? null : cookie.Value);
        }
 protected string GetCookies(CookieKeys key)
 {
     return(GetCookies(key + ""));
 }
 protected void DeleteCookies(CookieKeys key)
 {
     DeleteCookies(key + "");
 }
 protected void SetCookies(CookieKeys key, string value, int minutes = 30)
 {
     SetCookies(key + "", value, minutes);
 }
 public void DeleteCookie(CookieKeys key)
 {
     this.DeleteCookie(key.ToString());
 }
 public string GetCookie(CookieKeys key)
 {
     return(this.GetCookie(key.ToString()));
 }
 public void SetCookie(string value, CookieKeys key)
 {
     this.SetCookie(value, key.ToString());
 }
        public static string Get(HttpContext context, CookieKeys key)
        {
            var cookieName = Keys[key];

            return(context.Request.Cookies[cookieName]);
        }
Exemple #17
0
        public static void SetCookie(CookieKeys key, string ownedToken)
        {
            HttpCookie savingCookie = new HttpCookie(key.ToString(), ownedToken);

            HttpContext.Current.Response.Cookies.Add(savingCookie);
        }