现在我从数据库中读取用户名和密码并验证了!怎么用cookie记住用户名或密码啊,我原来是用的session,查资料才知道session是保存在服务器上的<table>
                        <tr>
                            <td width="60">Email</td>
                            <td> <asp:TextBox ID="TextBox3" runat="server" Width="124px"></asp:TextBox></td>
                        </tr>
                        <tr>
                            <td>密码
                               </td>
                            <td>
                                <asp:TextBox ID="TextBox4" runat="server" TextMode="Password" Width="124px"></asp:TextBox></td>
                        </tr>
                         <tr>
                            <td>验证码
                               </td>
                            <td>
                                <asp:TextBox ID="TextBox1" runat="server" Width="62px"></asp:TextBox><img alt="验证码" src="shopValidateCode.aspx" title="点击" style=" margin-bottom:-5px; cursor:pointer;" onclick="this.src='shopValidateCode.aspx?id='"+Math.random()+"'" /></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <asp:CheckBox ID="CheckBox1"  runat="server" Checked="True" />记住用户名 </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td style="height:60px;">
                                <asp:ImageButton ID="ImageButton1" runat="server"  
                                    ImageUrl="~/images/but_login.gif" onclick="ImageButton1_Click" /> 
                               </td>
                        </tr>
                    </table>后台:
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string email = Server.HtmlEncode(TextBox3.Text); 
        string pwd = Server.HtmlEncode(TextBox4.Text);
        Model.user mod = new Model.user();
        mod.email = email;
        mod.pwd = pwd;        BLL.user bll = new BLL.user();
        SqlDataReader  dr = bll.login(mod);
        //ds.Tables[0].Rows[0]["_userid"];
        if (CheckBox1.Checked)
        {
            SqlDataReader dr1 = bll.lo(mod); /*读session内容*/
            if (dr1.Read())
            {
                Session["_username"] = dr1["_username"].ToString(); /*记用户名*/
                Session["_userid"]=dr1["_userid"].ToString();
               
                dr1.Close();
            }
            dr1.Close();
        }
        else
        {
            Session["_username"] = "";
        }        if (Session["CheckCode"] != null)
        {
            
            if (TextBox1.Text.ToLower() == Session["CheckCode"].ToString().ToLower()) /*验证码的方法*/
            {
                
                if (dr.Read())
                {
                    Response.Redirect("ACIndex.aspx");
 {
                    Common.MessageAlert.Alert(Page, "登入失败!");
                }            }
            else
            {
                Common.MessageAlert.Alert(Page, "验证码错误!");
                
            }我想用cookie的方法请问应怎么做呢

解决方案 »

  1.   

    Response.Cookies["list"]["Name"] = StringUtil.Encrypt(list[0].UserName, StringUtil.myKey);
                    Response.Cookies["list"]["id"] = StringUtil.Encrypt(list[0].UserId.ToString(), StringUtil.myKey);
                    Response.Cookies["list"]["type"] = StringUtil.Encrypt(list[0].IsAdmin.ToString(), StringUtil.myKey);
      

  2.   

        这个是写      
                HttpCookie cook = new HttpCookie("abc");
                cook.Values.Add("login1", a);
                Response.Cookies.Add(cook);
    这个是读
                HttpCookie aa = Request.Cookies["abc"];
                Label12.Text = aa.Values["login1"].ToString();
      

  3.   

    HttpCookie cookie = cookie = new HttpCookie("UserInfo");
    cookie.Values.Set("Name", Name);
    cookie.Values.Set("Password", Password);
    Response.AppendCookie(cookie);System.Web.HttpCookie newcookie = new HttpCookie("user");
    newcookie.Values["username"] = "";
    newcookie.Values["password"] = "";
    newcookie.Expires = DateTime.Now.AddDays(15);
    Response.AppendCookie(newcookie);
    HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies[cookiename];  
    if (cookie != null)  
    {  }