Keep-Alive

Overview

Persistent HTTP connections, using Connection: Keep-Alive headers, provide one method by which you can improve performance for your Web application. In general, if both your application and the client have requested a persistent HTTP connection, IIS will continue to reuse the TCP/IP socket that was used to receive the initial browser request, instead of destroying it and creating a new socket for each and every additional request.

This sample extension demonstrates how you can make use of persistent connection from within your own ISAPI extension.

Code Tour

When an instance of this extension is created, and the HttpExtensionProc entry point function is called by the server, this extension creates a special header that includes the Connection: Keep-Alive element. The Content-Length header element is also set, so that the client browser knows when the server has completed transmission. As part of the response, a form button is sent to the client browser so the user can re-access the extension easily. Note that the extension returns the status code HSE_STATUS_SUCCESS_AND_KEEP_CONN, which requests that the server keep the socket connection open.

Note   If the request to your ISAPI extension comes from a client browser that supports HTTP 1.1, such as Internet Explorer version 4.0 or later, and HTTP 1.1 is enabled, then HTTP connections will persist by default. This is functionally equivalent to both the client and the server including Connection: Keep-Alive headers with every HTTP request and response. When HTTP 1.1 is in use, the Connection: Keep-Alive header is considered redundant.

Location

This project is available in the ...isapi\extensions\Keep-Alive subdirectory of the IIS samples directory.