首页 新闻 会员 周边

Cookie存到本地了,为什么读不到!希望大侠们指点下

0
悬赏园豆:5 [待解决问题]
写入Cookie

            if (bll.UserLogin(loginUser, loginPwd, out msg, out userModel))
            {
                Session["currUser"] = userModel;
                if (cbAutoLogin.Checked)
                {
                    HttpCookie c1 = new HttpCookie("cp1", userModel.LoginId);
                    HttpCookie c2 = new HttpCookie("cp2", this.JiaMi(userModel.LoginPwd));
                    c1.Expires = DateTime.Now.AddDays(7);
                    c2.Expires = DateTime.Now.AddDays(7);

                    Response.Cookies.Add(c1);
                    Response.Cookies.Add(c2);

                }
                GoPage();
            }


读取Cookie
  protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies["cp1"] != null && Request.Cookies["cp2"] != null)
            {
                string a = Request.Cookies["c1"].Value;
                string b = Request.Cookies["c2"].Value;
                UsersModel model = bll.GetMode(a);
                if (model!=null && model.UserState.Name=="正常")
                {
                    string result = this.JiaMi(model.LoginPwd, b.Substring(0, 2));
                    if (result==b)
                    {
                        Session["currUser"] = model;
                        GoPage();
                    }
                }

            }

        }

为什么           if (Request.Cookies["cp1"] != null && Request.Cookies["cp2"] != null)会始终为空?希望大侠指点一下

残阳tt的主页 残阳tt | 初学一级 | 园豆:166
提问于:2014-03-25 17:12
< >
分享
所有回答(2)
0

那你的 Fillder 抓取下,看看请求和响应中是否有 Cookie。

Launcher | 园豆:45045 (高人七级) | 2014-03-25 17:14

但是写Cookie的时候有

支持(0) 反对(0) 残阳tt | 园豆:166 (初学一级) | 2014-03-25 17:20

@残阳tt: 你把抓包贴出来,看下请求和响应

支持(0) 反对(0) Launcher | 园豆:45045 (高人七级) | 2014-03-25 17:27

@Launcher: 谢谢了。调出来了,是浏览器上对Cookie进行设置了

支持(0) 反对(0) 残阳tt | 园豆:166 (初学一级) | 2014-03-26 23:16
0

客户端是否禁用cookie?

string a = Request.Cookies["c1"].Value;
string b = Request.Cookies["c2"].Value;

这地方是否正确?c1,c2?

wolfy | 园豆:2636 (老鸟四级) | 2014-03-26 13:03

有值的,谢谢了。调出来了,是浏览器上对Cookie进行设置了

支持(0) 反对(0) 残阳tt | 园豆:166 (初学一级) | 2014-03-26 23:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册