//写入
protected void Button1_Click(object sender, EventArgs e)
{
if (Request.Cookies[cookiename] == null)
{
HttpCookie cookie = new HttpCookie(cookiename);
cookie["IP"] = txtIP.Text;
Response.Cookies.Add(cookie);
}
else
{
Response.Cookies[cookiename]["IP"] = txtIP.Text;
// Response.Write("<script>alert('已存在');</script>");
}
}
//读取
protected void Button2_Click(object sender, EventArgs e)
{
HttpCookie cookie = Request.Cookies[cookiename];
if (cookie!=null)
{
txtReadIP.Text = cookie["IP"];
}
}