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);
            }
        } 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM