創建
HttpCookie cookie = new HttpCookie("name");
cookie.Value = HttpUtility.UrlDecode("豬剛烈", Encoding.GetEncoding("UTF-8")); //HttpUtility 這個是用來編碼 解碼的
cookie.Expires = DateTime.Now.AddDays(1); //設置過期時間
Response.Cookies.Add(cookie);
讀取
TextBox1.Text = HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies["name"].Value, Encoding.GetEncoding("UTF-8"));
刪除 只要將過期時間設為負數就刪除了。。
HttpCookie cookie = new HttpCookie("name");
cookie.Expires = DateTime.Now.AddDays(-21);
Response.Cookies.Add(cookie);