Looking for a C# demo that reads and writes to a cookie

Posted on 2011-10-10
Last Modified: 2012-05-12
I would like to download a C# program which writes to a cookie then also reads that cookie and its value, the second time.

Question by:newbieweb
    LVL 35

    Assisted Solution

    by:Miguel Oz
    LVL 11

    Accepted Solution


    Writing Cookies
    Response.Cookies["userName"].Value = "patrick";
    Response.Cookies["userName"].Expires = DateTime.Now.AddDays(1);

    HttpCookie aCookie = new HttpCookie("lastVisit");
    aCookie.Value = DateTime.Now.ToString();
    aCookie.Expires = DateTime.Now.AddDays(1);

    Reading Cookies:
    if(Request.Cookies["userName"] != null)
        Label1.Text = Server.HtmlEncode(Request.Cookies["userName"].Value);

    if(Request.Cookies["userName"] != null)
        HttpCookie aCookie = Request.Cookies["userName"];
        Label1.Text = Server.HtmlEncode(aCookie.Value);
    Below link will give you full detailed information about cookies
    LVL 17

    Assisted Solution


    Author Closing Comment


    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    728 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

    20 Experts available now in Live!

    Get 1:1 Help Now