【转】创建COOKIE

记录COOKIE
       HttpCookie username = new HttpCookie("username");
        HttpCookie autolog = new HttpCookie("autologon");
        username.Value = TextBox1.Text;
        autolog.Value = CheckBox1.Checked.ToString();
        //保存一年
        username.Expires = DateTime.Today.AddYears(1);
        autolog.Expires = DateTime.Today.AddYears(1);
        Response.Cookies.Add(username);
        Response.Cookies.Add(autolog);

在FORM_LOAD中读取COOKIE
        if (Request.Cookies["username"]!= null)
        {
            TextBox1.Text = Request.Cookies["username"].Value;
            CheckBox1.Checked = bool.Parse(Request.Cookies["autologon"].Value);
        }

posted @ 2012-11-19 09:08  小林叔叔  阅读(156)  评论(0)    收藏  举报