發(fā)布時間:2017-06-24 14:11 作者:獨孤劍 閱讀:1100
protected void Button1_Click(object sender, EventArgs e) { // 設置 cookie, 將內(nèi)容進行編碼存儲 HttpCookie cookie = new HttpCookie("cookie", HttpUtility.UrlEncode("中文/abc")); // 過期時間 cookie.Expires = DateTime.Now.AddDays(+1); Response.Cookies.Add(cookie); Response.Redirect("Default.aspx"); }
獲取 cookie
protected void Page_Load(object sender, EventArgs e) { HttpCookie cookie = default(HttpCookie); cookie = Request.Cookies.Get("cookie"); // 判斷是否為空 if (cookie != null) { // 進行解碼 string str = HttpUtility.UrlDecode(cookie.Value); Response.Write(str); } else { // cookie 對象為空 } }
微信打賞, 微信掃一掃
支付寶打賞, 支付寶掃一掃
如果文章對您有幫助,歡迎給作者打賞