//将参数包含在json中,由cookie携带 public void WriteCookie1() { DisplaySeeting setting = new DisplaySeeting() { Style = 5, Size = 36 }; string json = HttpUtility.UrlEncode(setting.toJosn(), Encoding.Default); HttpCookie cookie = new HttpCookie("settings", json); Response.Cookies.Add(cookie); }
private void WriteCookie() { DisplaySeeting setting = new DisplaySeeting { Style = 5, Size = 24 }; HttpCookie cookie = new HttpCookie("settings"); cookie["Style"] = setting.Style.ToString(); cookie["Size"] = setting.Size.ToString(); Response.Cookies.Add(cookie); }
private void ReadCookie() { DisplaySeeting setting = new DisplaySeeting(); HttpCookie cookie = Request.Cookies["settings"]; if (cookie == null) { Label1.Text = "未定义"; } else { setting.Style = Convert.ToInt32(cookie["Style"]); setting.Size = Convert.ToInt32(cookie["Size"]); Label1.Text = setting.ToString(); } }