分类: WINDOWS
2011-03-18 17:04:22
Whenever an extension is accessed (e.g., & Tx=870250AZT6), IIS checks to see whether the example.dll is loaded into memory. If it is not, then it initiates the loading process. Once the DLL is loaded into memory, a worker thread starts running to manage our extension, and thereafter the entry point (DLLMain function) is called.
When the DLLMain finishes, the server makes a call to GetExtensionVersion function to perform two tasks:
The server then calls the HttpExtensionProc function passing a copy of the ECB's pointer to start the actual ISAPI extension. This is the function that makes writing data back to the client。
For an ISAPI extension to be used by IIS, it must
provide a standard interface. To provide a standard interface, each
ISAPI extension DLL must implement and export two primary functions, and . A third function, , is optional and is commonly used by extensions to perform cleanup operations.
Initialization Using GetExtensionVersion
Initialization is handled by the entry-point function .
This function's role is to perform all initialization, including the
creation of worker threads, synchronization objects, and database
connections, and to establish the version of ISAPI that was used to
build the DLL.
Adding Functionality Using HttpExtensionProc
When an extension is no longer needed, IIS removes it from memory. If the extension provides the function, IIS calls it before removing the extension. Use of is recommended to close down any threads that an extension initialized during processing.
After IIS finishes processing a request for an ISAPI extension, the connection can either be closed or kept open. A request can specify that the connection remain open by specifying the Connection: Keep-Alive header. If an ISAPI extension is designed to support Keep-Alive requests, this should be indicated to the client by calling the server support function. The specified response header should contain Connection: Keep-Alive.
DWORD SendHeaderToClient(LPEXTENSION_BLOCK pECB) {
CHAR szHeader[] = "Content-type: test/html\r\n\r\n";
DWORD hseStatus = HSE_STATUS_SUCCESS;
BOOL fReturn = pECB->ServerSupportFunction(pECB->ConnID,
HSE_REQ_SEND_RESPONSE_HEADER,
"Connection:Keep-Alive" // Telling the client not to close the connection.
NULL,
(LPDWORD) szHeader
);
if (!fReturn) hseStatus = HSE_STATUS_ERROR;
return hseStatus;
}
还有一个很好的介绍isapi extension的地址: