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