Cookies in an ISAPI Extension DLL

I was designing an ISAPI .dll for use on our website, and quickly discovered what little information is available regarding the use of cookies on an MFC server side ISAPI extension. For login purposes, the cookies were absolutely essential. Hopefully this code will save somebody the R&D I had to go through...

First of all, let's talk about how cookies work. Cookies are basically just variables, and can be VERY useful in state management, user identification, etc. Cookies are set and retrieved via the HTTP headers. To create a cookie, the server includes a "Set-Cookie" command in the header. After a cookie is set, the client will pass the cookies and their values to the server in the header of every HTTP request. More details of what to send and what is received can be found at

Below find source code for a CCookie class, with member functions GetCookie, SetCookie, and EnumCookies; as well as a sample ISAPI project.

To use the sample project, simply build it, and place ISAPICookies.DLL in your WWWROOT directory (make sure you have execute access enabled for that directory); then direct your browser to http://localhost/ISAPICookies.DLL

Feel free to contact me with any questions or comments.


Download demo project - 14 Kb


  • Cookie value not retrieved using filters

    Posted by Legacy on 06/23/2003 12:00am

    Originally posted by: Maneet Singh Khurana


    Getting an IDEA from ISAPI extensions, I added a cookie using Response.Cookies and tried to retrieve its value using ISAPI filters. In the OnPreProcHeaders() event, no value is retrieved for the cookie that I had set.

    Please help.
    Thanks in advance

  • how to set a cookie with expiration date ?

    Posted by Legacy on 03/31/2003 12:00am

    Originally posted by: iwaitu

    Who can give me a sample ??

  • how can I run the ISAPI extension?

    Posted by Legacy on 12/24/2002 12:00am

    Originally posted by: Ting Jung Yen

    I am new to the ISAPI.I try to run a short DLL wrote in ISAPI,but the browser ask me to download into somewhere or open it with certain tool every time I run that dll.
    Do I need to do some set-up procedure before I can use browser to run my short ISAPI DLL?especially for the ISAPI extension

  • Adding two cookies in ISAPI Filter

    Posted by Legacy on 10/14/2002 12:00am

    Originally posted by: jeongj

    In ISAPI Filter,
    I used the function "AddResponseHeaders" twice to add two cookies in the member function "OnPreprocHeaders"
    as the followings

    DWORD CanyFilter::OnPreprocHeaders(CHttpFilterContext* pCtxt,
    pCtxt->m_pFC->AddResponseHeaders(pCtxt->m_pFC, "Set-Cookie: companyID=big123;expires=Fri 22-May-2050 13:00:00 GMT;; path=/;\r\n;", 0);
    pCtxt->m_pFC->AddResponseHeaders(pCtxt->m_pFC, "Set-Cookie: departID=fin12;expires=Fri 22-May-2050 13:00:00 GMT;; path=/;\r\n;", 0);

    The first cookie(companyID) was saved in the Client webrowser but the second cookie(departID) was not saved.

    Is there wrong in using the "AddResponseHeaders" in OnPreprocHeaders?

    I need help.



  • Posted by Legacy on 06/07/2002 12:00am

    Originally posted by:

  • debugging

    Posted by Legacy on 10/18/2001 12:00am

    Originally posted by: nam yun chool

    I'd like to know how to debug the dll produced.
    I am korean.
    and beginner.

    Thank you very much!

  • Debugging

    Posted by Legacy on 10/16/2001 12:00am

    Originally posted by: Francesco Vitale

    I'd like to know how to debug the dll produced.
    Thank you very much!


  • How can I........

    Posted by Legacy on 04/27/2001 12:00am

    Originally posted by: Devdatta Patil

    I am trying to send an email to myself by using MAPI control, while runnuing for the first time it works but after that following function at line (*) gives an error 'Unspecified failure has occured'.

    Public Function sendEmail()
    MAPIMessages.SessionID = MAPISession.SessionID
    MAPIMessages.RecipAddress = ""
    MAPIMessages.MsgSubject = "Test Message"
    MAPIMessages.MsgNoteText = "Hi! how are you?"
    MAPIMessages.Send False *
    End Function

    Please help me


  • how can i know whether the user's cookies have been disabled?

    Posted by Legacy on 11/24/2000 12:00am

    Originally posted by: Leon

    If the user has never vistied my website,when I get his cookie,I get a empty cookie.
    Can I know he is a new user(don't disable cookie) or he is an old user(he disabled his cookie)?

  • How can I clear cookie?

    Posted by Legacy on 09/22/2000 12:00am

    Originally posted by: Tehrani

    How can I clear cookie?

    I set cookie but can not clear it...

  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • As mobile devices have pushed their way into the enterprise, they have brought cloud apps along with them. This app explosion means account passwords are multiplying, which exposes corporate data and leads to help desk calls from frustrated users. This paper will discover how IT can improve user productivity, gain visibility and control over SaaS and mobile apps, and stop password sprawl. Download this white paper to learn: How you can leverage your existing AD to manage app access. Key capabilities to …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds