CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Feb 2007
    Location
    Cat Square (near Charlotte)
    Posts
    16

    Cookie confusion

    Hello all...

    I am working through an asp.net 2.0 book, and have a question about cookies. The book makes it appear as though it is possible to have multiple cookies, but all of my data is appearing in the same .txt file. In my page_load() function, I have this code snippet.

    Code:
    // define the cookie 
    Response.Cookies["lastVisit"].Value = DateTime.Now.ToString();
    Response.Cookies["lastVisit"].Expires = DateTime.Now.AddDays(1);
    
    Response.Cookies["userName"].Value = "John Smith";
    Response.Cookies["userName"].Expires = DateTime.Now.AddDays(1);
    
    Response.Cookies["favoriteColor"].Value = "blue";
    Response.Cookies["favoriteColor"].Expires = DateTime.Now.AddDays(1);
    The book leads me to believe that this would cause three separate cookies to be created, but I am getting one .txt file created, which if I look at it, has these three values stored in it. The book indicates that if you want to have multiple values stored in the same cookie, your code would look more like this:
    Code:
    Response.Cookies["userData"]["lastVisit"].Value = DateTime.Now.ToString();
    Response.Cookies["userData"]["userName"].Value = "John Smith";
    Response.Cookies["userData"]["favoriteColor"].Value = "blue";
    Response.Cookies["userData"].Expires = DateTime.Now.AddDays(1);
    I haven't even tried the second code, because I'm confused as to why I am only getting one .txt file (which I am assuming is my cookie) created.

    Any insight? Thanks in advance.

    TOOLS: VS 2005
    BROWSER: IE 6.0
    Last edited by ronmoles; December 19th, 2007 at 05:56 PM.
    C# - Visual Studio 2005
    Frameworks 2.0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured