Strange behavior with HttpCookieCollection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • adlaird@earthlink.net

    #1

    Strange behavior with HttpCookieCollection

    Hi,

    I created a simple webform, put a test button on it and implemented a
    click handler that looks like so:

    private void btnTest_Click(o bject sender, System.EventArg s e)
    {
    HttpCookieColle ction oCookReq =
    HttpContext.Cur rent.Request.Co okies;
    HttpCookieColle ction oCookResp =
    HttpContext.Cur rent.Response.C ookies;

    int n1 = oCookReq.Count;
    int n2 = oCookResp.Count ;
    bool bIsNull = (oCookResp["someCookieName "] == null);
    int n3 = oCookReq.Count;
    int n4 = oCookResp.Count ;

    Response.Write( string.Format(" Before: Request = {0}, Response
    = {1}<br>", n1, n2));
    Response.Write( string.Format(" After: Request = {0}, Response
    = {1}<br>", n3, n4));
    }


    When I click the button the test output on the page is:

    Before: Request = 1, Response = 0
    After: Request = 2, Response = 1

    Can anyone explain why the mere act of looking for a cookie in the
    response collection would cause one to get added to both the response
    and request collections? I tried the test again using a new
    HttpCookieColle ction (i.e. not one from the current context) and do
    not get this behavior. Clues?

    Thanks much...

    - A

Working...