读取Cookies

来源:互联网 发布:网络高清摄像头安装图 编辑:程序博客网 时间:2024/05/15 23:44

  protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies["hh"] != null)
            {
                HttpCookie hc = Request.Cookies["hh"] as HttpCookie;
               
               Response.Write("Name=" +hc.Values["name"].ToString()+"<br>Age="+hc.Values["age"].ToString());
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            HttpCookie hc = new HttpCookie("hh");
            hc.Values["name"] = "jn";
            hc.Values["age"] = "2";
            HttpContext.Current.Response.AppendCookie(hc);
            Response.Redirect("ttt.aspx", false);
        }

原创粉丝点击