Microsoft KB Archive/238554

= How To Prevent MFC ISAPI Extensions from Returning a Default Set of Headers =

Article ID: 238554

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Visual C++ .NET 2003 Standard Edition
 * Microsoft Visual C++ 5.0 Standard Edition
 * Microsoft Visual C++ 6.0 Service Pack 5
 * Microsoft Visual C++ .NET 2002 Standard Edition
 * Microsoft Internet Server Application Programming Interface 4.0
 * Microsoft Internet Information Services 5.0

-



This article was previously published under Q238554



SUMMARY
Unexpected behavior may occur when sending headers from an MFC ISAPI extension. This may be due to the ISAPI Extension sending multiple sets of headers. You can avoid this problem by setting the m_bSendHeaders flag to false in the ISAPI request handler.



MORE INFORMATION
The following code will return a "302 object moved" response to a client: void CSendURLExtension::Default(CHttpServerContext* pCtxt) {  char szUrl[] = "http://server/test/ok.htm"; DWORD dwUrlSize = sizeof(szUrl);

pCtxt->ServerSupportFunction(HSE_REQ_SEND_URL, (void*)szUrl,       &dwUrlSize, NULL); } Most Internet browsers react to a 302 response by automatically requesting a the new URL. In the code above, however, some browsers respond with a "400 Bad Request" error.

The best way to diagnose such a problem is to "sniff" the communication between the client and server. You can do this with a number of tools including the NetMon program included with Microsoft SMS Server. In the above case, the following transaction occurs: (not all headers are shown)

Client request resource: HTTP: GET Request (from client using port 1524) HTTP: Request Method = GET HTTP: Uniform Resource Identifier = /isapi/SendURL.dll? HTTP: Protocol Version = HTTP/1.1 HTTP: Host = uncle HTTP: Connection = Keep-Alive

Server responds: HTTP: Response (to client using port 1524) HTTP: Protocol Version = HTTP/1.1 HTTP: Status Code = Found HTTP: Reason = Object Moved HTTP: Undocumented Header = Location: /ok.htm Server also responds: HTTP: Response (to client using port 1524) HTTP: Protocol Version = HTTP/1.1 HTTP: Status Code = OK     HTTP: Reason = OK      HTTP: Connection = close This response sequence is invalid. The server is sending a "302 object moved" response followed by a "200 OK" response. The client in this case responds to the 302 not expecting another response. The second response contains notification to the client that the connection has been closed. The client, unaware of this, requests the new page over a connection that has been closed and an error occurs. Please note that client ports may vary and 1524 is used as a sample.

The solution here is to prevent MFC from sending the default headers as in the following code: void CSendURLExtension::Default(CHttpServerContext* pCtxt) {       pCtxt->m_bSendHeaders = FALSE; char szUrl[] = "http://server/test/ok.htm"; DWORD dwUrlSize = sizeof(szUrl);

pCtxt->ServerSupportFunction(HSE_REQ_SEND_URL, (void*)szUrl,            &dwUrlSize, NULL); }

