2013-04-04 91 views
1

我在下面的代码片段中设置了一个cookie。当我在萤火虫中查看我的饼干时,我看到了饼干,但是这个值本身是空白的。
我知道respondArray[1]变量是一个字符串,但它只是不保存到cookie中。asp.net cookie不存储的值

System.Web.HttpCookie cookie = new System.Web.HttpCookie("secretKey", respondArray[1]); 
Response.Cookies.Add(cookie); 

任何帮助,非常感谢。

+0

你说的秘密密钥[1],但您使用respondArray [1]。这是好的,也许这是错误? – Dave 2013-04-04 12:53:44

回答

1

试试这可帮助您

HttpCookie userCookie = new HttpCookie("UserInfo"); 
     userCookie["Country"] = "Italy"; 
     userCookie["City"] = "Rome"; 
     userCookie["Name"] = "Jones"; 


if (cookie != null) 
     { 
      string country = cookie["Country"]; 
      string city = cookie["City"]; 
      string name = cookie["Name"]; 
      Label2.Text = "Cookie Found and read<br/>"; 
      Label2.Text += "Name: " + name; 
      Label2.Text += "<br />Country: " + country; 
      Label2.Text += "<br />City: " + city; 
     } 
+1

使用该代码我甚至没有得到空白曲奇:( – 2013-04-05 09:05:55

+0

让我看看你的代码 – 2013-04-05 09:08:56

+0

我发现设置曲奇我原来的方式(和你的方式)都工作,只要我不重定向后,这是一项要求...是否有重定向和Cookie我不知道的问题? – 2013-04-05 09:46:03