Sending CookiesA cookie is sent to the client by the server in an HTTP "Set-Cookie:" header This header can be added in an ISAPI filter with the AddResponseHeaders member function in the HTTP_FILTER_CONTEXT structure passed to the filter notification.:
PFC-> AddResponseHeaders (PFC, "SET-Cookie: cookie1 = value1; path = /; / r / n",
0);
In the above example, "Cookie1" is the name of the cookie and "Value1" is the value of the cookie. The "path = /" attribute tells the client to return the cookie with all requests to that server. If unspecified, the client assumes the path to be the same as that of the requested resource.NOTE:. If you are adding the header within the SF_NOTIFY_SEND_RESPONSE handler, you should use the AddHeader member of the HTTP_FILTER_SEND_RESPONSE structure rather than AddResponseHeaders For more information on AddResponseHeaders, see the Platform SDK Documentation or The Following Microsoft Developer Network (MSDN) Web Site:
http://msdn.microsoft.com/library/psdk/iisref/isre9uur.htm
A cookie can also be added as an additional header in a call to serversupportfunction from Withn ISAPI EXTENSION:
Char szheader [] = "set-cookie: cookie2 = value2; path = /; / r / nContent-type:
TEXT / HTML / R / N / R / N ";
DWORD DWSIZE;
DWSIZE = Strlen (Szheader);
LPECB-> ServersupportFunction (LPECB, HSE_REQ_SEND_RESPONSE_HEADER,
NULL, & DWSIZE, (UNSIGNED Long *) szheader;
In an MFC Isapi Extension, Headers Should Not Be Sent In this Way; Instead, Add The cookie to the output stream with the addheader function:
Char szheader [] = "set-cookie: cookie2 = value2; path = /; / r / n";
STARTCONTENT (PCTXT);
AddHeader (PCTXT, Szheader);
Note that the content type does not need to be "text / html"; cookies will work for any content type.Retrieving CookiesA cookie is returned to the server by the client in an HTTP "Cookie:". Header Multiple cookies can appear in this . header, separated by semicolons This header can be retrieved in an ISAPI filter responding to the SF_NOTIFY_PREPROC_HEADERS notification using the GetHeader member function in the HTTP_FILTER_PREPROC_HEADERS structure:
DWORD WINAPI HTTPFILTERPROC (http_filter_context * pfc,
DWORD NOTIFICATIONTYPE, VOID * PVNOTIFICATION)
{
HTTP_FILTER_PREPROC_HEADERS * PPH;
Char szbuffer [4096];
DWORD DWSIZE = 4096;
PPH = PVNOTIFICATION;
PPH-> GetHeader (PFC, "Cookie:", SZBuffer, & DWSize
RETURN SF_STATUS_REQ_NEXT_NOTIFICATION;
}
Or, a cookie can be retrieved in Either A Filter or Extension Using The GetServerVariable Member Function In The http_filter_context and extension_control_block structures:
Char szbuffer [4096];
DWORD DWSIZE = 4096;
In a filter:
PFC-> GetServerVariable (PFC, "HTTP_COOKIE", SZBuffer, & DWSIZE
OR, IN AN Extension:
PECB-> GetServerVariable (PECB, "http_cookie", szbuffer, & dwsize);
Cookie PersistenceThe cookies in the above examples will only be maintained by the client until the user exits the browser. The server can cause a cookie to be maintained by a browser for a longer period by specifying an "expires" attribute. This will cause the browser To store the cookie and continue returning it to the server with each request, untric the cookie is expedition:
PFC-> AddResponseHeaders (PFC, "SET-Cookie: cookie1 = value1;
Expires = fri 22-May-1998 13:00:00 gmt; path = /; / r / n ", 0);