asp.net cookie没有存储值

时间:2013-04-04 11:01:01

标签: asp.net .net

我在asp中使用以下代码片段设置了一个cookie。当我在firebug中查看我的cookie时,我看到了cookie,但值本身是空白的。我知道respondArray[1]变量是一个字符串,但它只是没有保存到cookie中。

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

非常感谢任何帮助。

1 个答案:

答案 0 :(得分: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;  
        }