Setting a Cookie to an array of values in C#

Posted on 2011-10-10
Last Modified: 2013-12-16
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];

Question by:newbieweb
    LVL 35

    Accepted Solution

    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:

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now