日期:2014-05-17  浏览次数:20406 次

【关于登陆cookies】的问题
当我关闭浏览器 从新打开浏览器的时候 就找不到cookie 说明我保存失败了.请问我该哪里写错了该怎么修改
C# code

            if (this.ddlstatus.SelectedValue == "普通用户")
            {
                if (BaseClass.CheckStudent(txtNum.Text.Trim(), txtPwd.Text.Trim()))
                {
                    Session["ID"] = txtNum.Text.Trim();
                    Session["name"] = txtNum.Text.Trim();
                    HttpCookie littcookie = new HttpCookie("UserloginName");
                    Response.Cookies["UserloginName"].Value = HttpUtility.UrlEncode(txtNum.Text, System.Text.Encoding.GetEncoding("gb2312"));
                     //Cookies保存用户名
                    Response.Cookies["UserloginName"].Expires = DateTime.Today.AddDays(30);  //设置过期时间, 

                    Tb_Student tb_Student = Tb_StudentManager.Instance.GetModelTb_StudentByWhere(" StudentNum='" + txtNum.Text.ToString() + "' ");
                    Session["danwei"] =tb_Student.Danwei.ToString();
                    Session["keshi"] = tb_Student.Keshi.ToString();//科室
                    Session["shouji"] = tb_Student.Tel.ToString();//科室
                    Response.Redirect("student/studentexam.aspx");
                }

//另一个页面如果判断。  
C# code
  try
            {
                if (Request.Cookies["UserloginName"] != null)
                {
                   string nemaeusel = HttpUtility.UrlDecode(Request.Cookies["UserloginName"].Value, System.Text.Encoding.GetEncoding("gb2312"));
                }


------解决方案--------------------
申明
C# code

HttpCookie cookie = new HttpCookie("test");
      cookie.Value = "二哥";
      cookie.Expires = DateTime.Now.AddDays(1);
      Response.Cookies.Add(cookie);