Reading a cookie in an ISAPI Filter RRS feed

  • Question

  • User-1039005448 posted

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

    Thank you

    Wednesday, November 28, 2007 3:46 PM

All replies

  • User511787461 posted

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

    Thursday, November 29, 2007 12:36 AM
  • User-1039005448 posted

                 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.
    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

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

    #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));

    Thursday, November 29, 2007 4:01 PM
  • User511787461 posted

    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.

    Wednesday, December 5, 2007 5:03 PM