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 http://www.netscape.com/newsref/std/cookie_spec.html

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.

Downloads

Download demo project - 14 Kb


Comments

  • Cookie value not retrieved using filters

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

    Originally posted by: Maneet Singh Khurana

    Hi!
    
    

    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
    Maneet

    Reply
  • 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 ??

    Reply
  • 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

    Reply
  • 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,
    PHTTP_FILTER_PREPROC_HEADERS pHeaderInfo)
    {
    .....
    pCtxt->m_pFC->AddResponseHeaders(pCtxt->m_pFC, "Set-Cookie: companyID=big123;expires=Fri 22-May-2050 13:00:00 GMT; domain=.test.com; path=/;\r\n;", 0);
    pCtxt->m_pFC->AddResponseHeaders(pCtxt->m_pFC, "Set-Cookie: departID=fin12;expires=Fri 22-May-2050 13:00:00 GMT; domain=.test.com; 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.

    Regards

    Jeongj

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

    Originally posted by:

    Reply
  • debugging

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

    Originally posted by: nam yun chool


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


    Thank you very much!


    Reply
  • Debugging

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

    Originally posted by: Francesco Vitale

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

    Francesco

    Reply
  • 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()
    MAPISession.SignOn
    MAPIMessages.SessionID = MAPISession.SessionID
    MAPIMessages.Compose
    MAPIMessages.RecipAddress = "devdatta@mstdinc.com"
    MAPIMessages.MsgSubject = "Test Message"
    MAPIMessages.MsgNoteText = "Hi! how are you?"
    MAPIMessages.Send False *
    MAPISession.SignOff
    End Function

    Please help me

    Thanks
    Devdatta

    Reply
  • 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)?

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

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • Learn How A Global Entertainment Company Saw a 448% ROI Every business today uses software to manage systems, deliver products, and empower employees to do their jobs. But software inevitably breaks, and when it does, businesses lose money -- in the form of dissatisfied customers, missed SLAs or lost productivity. PagerDuty, an operations performance platform, solves this problem by helping operations engineers and developers more effectively manage and resolve incidents across a company's global operations. …

  • Live Event Date: December 18, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this upcoming webcast …

Most Popular Programming Stories

More for Developers

RSS Feeds