  using System;
  using System.Collections.Generic;
  
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  
  public partial class CookieDemo : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              HttpCookie readcookie = Request.【Cookies】["user"];
              if (readcookie != null)
                  TextBox1.Text = readcookie.【Value】;
          }
      }
  
      protected void Button1_Click1(object sender, EventArgs e)
      {
          HttpCookie cookie = new 【HttpCookie】("user");
          DateTime dt = DateTime.【Now】;
          TimeSpan ts = 【new】 TimeSpan(0, 0, 6, 0);
          cookie.Expires = dt.【Add】(ts);
          cookie.Value = TextBox1.Text;
          Response.【AppendCookie】(cookie);
          Response.Write("用户名已存入cookie,请重新打开网页验证");
          Response.Write("<BR>");
      }
  }
