标题:cookie无法存储
只看楼主
wy508510
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-3-22
结帖率:0
已结贴  问题点数:20 回复次数:1 
cookie无法存储
if ((Users)Session["currentUser"] != null)
  {
  this.lblUser.Text = "";
  this.imgbtnComplaint.Enabled = true;
  this.imgbtnLink.Enabled = true;
  user = (Users)Session["currentUser"];
  string userId = "xikemen"+user.UserId.ToString();
  if (Request.Cookies[userId] == null)
  {
  HttpCookie cookieNew = new HttpCookie(userId);
  cookieNew.Expires = DateTime.Now.AddDays(30);

  cookieNew.Values.Add("Clicked", "");
  string ids = Request.QueryString["id"].ToString() + ",";
  cookieNew.Values.Add("looked", ids);
  //Response.AppendCookie(cookie);
  //Response.SetCookie(cookie);
  Response.Cookies.Add(cookieNew);
  }
  else
  {
  HttpCookie cookieNew = Request.Cookies[userId];
  if (cookieNew["looked"] == null)
  {
  string ids = Request.QueryString["id"].ToString() + ",";
  cookieNew.Values.Add("looked", ids);
  }
  else
  {
  if (cookieNew["looked"].Contains(Request.QueryString["id"].ToString()))
  {
  }
  else
  {
  cookieNew["looked"] += Request.QueryString["id"].ToString() + ",";
  }
  }
  // Response.AppendCookie(cookie);
  Response.Cookies.Add(cookieNew);
  //Response.SetCookie(cookie);
  }
我写的这样一段代码 请问是不是哪里有问题?为什么cookie无法存储到客户端?
搜索更多相关主题的帖子: cookie null 
2011-03-22 11:20
zhp223
Rank: 5Rank: 5
等 级:职业侠客
帖 子:99
专家分:362
注 册:2010-3-21
得分:20 
if (Request.Cookies[userId] == null)
应该是 Response.Cookies吧

日有所思,夜有所梦
2011-03-22 11:58



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-334392-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.339911 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved