保存Cookie 以保存username 和userPhone为例子
代码语言:javascript复制 //保存Cookie 方法一
Response.Cookies["username"].Expires = DateTime.Now.AddDays(1.0);
Response.Cookies["username"].Value = this.txtCookie.Text;
//保存Cookie 方法二
HttpCookie cookie = new HttpCookie("userPhone","123456");
cookie.Expires = DateTime.Now.AddDays(1.0);
Response.Cookies.Add(cookie);
读取Cookie
代码语言:javascript复制 Response.Write($"username={Request.Cookies["username"].Value} userPhone={Request.Cookies["userPhone"].Value}");