欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

c#cookie读取写入操作

程序员文章站 2023-03-25 19:04:09
public static void SetCookie(string cname, string value, int effective) { HttpCookie cookie = new HttpCookie(cname); cookie.Value = value; cookie.Expi... ......
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);
            }
        }