Пример #1
0
        public static string RecuperaCookie(string id, bool clear = false)
        {
            string valor = string.Empty;

            try
            {
                HttpCookie cookie = HttpContext.Current.Request.Cookies[id];

                if (cookie != null)
                {
                    if (!string.IsNullOrEmpty(cookie.Value))
                    {
                        valor = Compactador.Descompactar(cookie.Value);
                    }
                }

                if (clear)
                {
                    cookie         = new HttpCookie(id);
                    cookie.Expires = DateTime.Now.AddDays(-1);
                    HttpContext.Current.Response.Cookies.Add(cookie);
                }
            }
            catch { }

            return(valor);
        }
Пример #2
0
        public static void GravaCookie(string id, string valor, int validadeEmMinutos)
        {
            try
            {
                var cookie = new HttpCookie(id, Compactador.Compactar(valor));
                cookie.Expires = DateTime.Now.AddMinutes(validadeEmMinutos);

                HttpContext.Current.Response.Cookies.Add(cookie);
            }
            catch { }
        }