Cookie Anomaly

Discussion in 'ASP .Net' started by Ash, Feb 26, 2004.

  1. Ash

    Ash Guest

    Hi

    I'm creating a cookie on my site, and adding values to it, namely a userid
    and a groupid:

    Function1:
    oCookie.Values["groupid"] = siteID.ToString();
    HttpContext.Current.Response.Cookies.Set(oCookie);

    Function2:
    oCookie.Values["userid"] = siteID.ToString();
    HttpContext.Current.Response.Cookies.Set(oCookie);

    where oCookie is created like this:

    HttpCookie oCookie = HttpContext.Current.Request.Cookies[CookieName];
    if (oCookie == null)
    {
    oCookie = new HttpCookie(CookieName);
    HttpContext.Current.Response.Cookies.Add(oCookie);
    }
    return oCookie;

    My problem is this:
    When I add the groupID, and then call Cookies.Set, a new Cookie with the
    same name is added to the Cookies Collection, instead of just setting the
    groupid value. ie, it creates two cookies, both with the groupid key and
    value. If I omit the Cookies.Set, the cookie is created only once, and
    everything is fine......

    except, when I do this with the userID, if I don't call Cookies.Set, the
    userID is not set to the cookie. If I do, the value/name pair is added to
    the existing cookie, like it should be.

    So, for clarity, these are the three scenarios:
    1. Add groupID, call Cookies.Set, Add userID call Cookies.Set = two Cookies
    created, both with the correct name value pairs.
    2. Add groupID, DON'T call Cookies.Set, Add userID call Cookies.Set = one
    Cookie created, both with the correct name value pairs. (DESIRED RESULT)
    3. Add groupID, call Cookies.Set, Add userID DON'T call Cookies.Set = one
    Cookie created, userID name/value pair not created.

    How much sense does this make?!?

    The setting of the groupid takes place before the userid, at different
    points in the application. oCookie always exists when the setting of these
    values take place. The cookie's a session cookie ie. doesn't persist.

    Any insight would be greatly appreciated.

    Ash
     
    Ash, Feb 26, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. clintonG

    What's this 2.0 compilation anomaly?

    clintonG, Dec 30, 2005, in forum: ASP .Net
    Replies:
    16
    Views:
    2,110
    clintonG
    Jan 5, 2006
  2. Dan
    Replies:
    0
    Views:
    360
  3. Roger Marquis

    util.regex.Pattern anomaly

    Roger Marquis, Aug 1, 2003, in forum: Java
    Replies:
    4
    Views:
    790
    Roger Marquis
    Aug 1, 2003
  4. NIO CPU Anomaly

    , Dec 14, 2004, in forum: Java
    Replies:
    3
    Views:
    524
    Esmond Pitt
    Dec 17, 2004
  5. Jonathan Amend

    IE 6 HTML rendering anomaly?

    Jonathan Amend, Apr 25, 2004, in forum: HTML
    Replies:
    2
    Views:
    378
    Jonathan Amend
    Apr 25, 2004
Loading...

Share This Page