写入Cookie
protected void Button1_Click(object sender, EventArgs e)
{
HttpCookie _ck = new HttpCookie("persion");
_ck.Value = HttpUtility.UrlEncode( "小杨");
_ck.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(_ck);
}
读取Cookie
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["persion"] != null)
{
string _s;
_s = Request.Cookies["persion"].Value;
Response.Write(HttpUtility.UrlDecode(_s));
}
}
红色标记不添加会导致读取Cookie“中文”乱码。
时间: 2024-10-09 01:35:10