Josh Undefined
Josh Undefined

Reputation: 1536

asp.net cookie not storing value

I'm setting a cookie in asp with the below snippet. When I look at my cookies in firebug I see the cookie however the value itself is blank.
I know the respondArray[1] variable is a string however it's just not saving into the cookie.

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

Any help is much appreciated.

Upvotes: 1

Views: 546

Answers (1)

Sagar Hirapara
Sagar Hirapara

Reputation: 1697

Try this may be help you

 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;  
        } 

Upvotes: 1

Related Questions