• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

Setting a Cookie to an array of values in C#

I need to write a cookie from an array of strings. I see the userCookie is a dictionary. But how could I use it as an array?  I need it for something like this:

    HttpCookie userCookie = new HttpCookie("myStringArray");
    userCookie["cell0"] = strArray[0];
    userCookie["cell1"] = strArray[1];
    userCookie["cell2"] = strArray[2];


Thanks.
0
newbieweb
Asked:
newbieweb
1 Solution
 
Miguel OzSoftware EngineerCommented:
You can save it as string:
userCookie["myArray"] = String.Join(",", strArray);

then when you read it back you split it:
HttpCookie cookie = Request.Cookies["myStringArray"];
string s = cookie["myArray"]
string[] strArray= s.Split(',');


Check for read/write cookies:
http://www.java2s.com/Code/ASP/Session-Cookie/CreateandretrieveCookiedataC.htm
0
 
newbiewebAuthor Commented:
Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now