« Previous Next »

Thread: Reading a cookie in an ISAPI Filter

Last post 12-05-2007 5:03 PM by anilr. 3 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (4 items)

Sort Posts:

  • 11-28-2007, 3:46 PM

    Reading a cookie in an ISAPI Filter

    Hi,
            Is there anyway, to read a domain level cookie in an ISAPI Filter.

    Thank you

  • 11-29-2007, 12:36 AM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 6:13 PM
    • Redmond, WA
    • Posts 2,343

    Re: Reading a cookie in an ISAPI Filter

    You can definitely read the cookie either using GetHeader("Cookie:", ...) or GetServerVariable("HTTP_COOKIE", ...) - you have to parse the cookie data yourselves.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 11-29-2007, 4:01 PM In reply to

    Re: Reading a cookie in an ISAPI Filter

    Hi,
                 Have a noticed this kind of behaviour anytime while trying to read a cookie in ISAPI Filter. For some reason, I can't get it to work using SetServerVariable.

     I have the code below.
     GetHeader
    char cookie[256];
    DWORD cookielen=256;
    pHeaderInfo->GetHeader(pfc,"Cookie:", cookie, &cookielen)
    if (cookielen > 0){
              
    x = pHeaderInfo->AddHeader(pfc,"MYUSER:", cookie); 
    }

    When I read the header using
    Request.Headers.Get("MYUSER"), I am getting ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ̉~±„üq'¤Z$W

    once, I refresh the test page, I can see the value that I am setting in the cookie.

    GetServerVariable
    #define bufferSize 4096 //increase size if using many cookies
    DWORD dwSize = bufferSize;
    char szBuffer[bufferSize] = "\0"; //NULL;

    pfc->GetServerVariable(pfc,"HTTP_COOKIE", szBuffer, &dwSize);
    if (strlen (szBuffer) > 0){
         x = pHeaderInfo->AddHeader(pfc,
    "MYUSER:", getUserName(szBuffer));
    }

  • 12-05-2007, 5:03 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 6:13 PM
    • Redmond, WA
    • Posts 2,343

    Re: Reading a cookie in an ISAPI Filter

    You need to check the return value of GetHeader/GetServerVariable - in case where there is no cookie sent by the client (eg in the first request) - those methods would fail, so you are using uninitialized memory to set the myuser header.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
Page 1 of 1 (4 items)
Microsoft Communities