c#cookie读取写入操作

public static void SetCookie(string cname, string value, int effective)
        {
            HttpCookie cookie = new HttpCookie(cname);
            cookie.Value = value;
            cookie.Expires = DateTime.Now.AddDays(effective);
            HttpContext.Current.Response.Cookies.Add(cookie);
        }

        public static object GetCookie(string cname)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[cname];
            return cookie;
        }

        public static void RemoveCookie(string name)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[name];
            if (cookie != null)
            {
                cookie.Expires = DateTime.Now.AddDays(-10);
                HttpContext.Current.Response.Cookies.Add(cookie);
            }
        } 

 

posted @ 2018-09-26 21:26  紅人  阅读(1537)  评论(0编辑  收藏  举报