CHttpModule::OnAsyncCompletion Method

IIS 7.0
 

Represents the method that will handle an asynchronous completion event, which occurs after an asynchronous operation has finished processing.

virtual REQUEST_NOTIFICATION_STATUS OnAsyncCompletion(
   IN IHttpContext* pHttpContext,
   IN DWORD dwNotification,
   IN BOOL fPostNotification,
   IN OUT IHttpEventProvider* pProvider,
   IN IHttpCompletionInfo* pCompletionInfo
);

pHttpContext

[IN] A pointer to an IHttpContext interface.

dwNotification

[IN] A DWORD value that contains the bitmask for the related notification.

fPostNotification

[IN] true to indicate that the notification is for a post-event; otherwise, false.

pProvider

[IN] A pointer to an IHttpEventProvider interface.

pCompletionInfo

[IN] A pointer to an IHttpCompletionInfo interface.

Unlike many of the other CHttpModule methods that are called by registering for specific notifications, IIS will call a module's OnAsyncCompletion method only when an asynchronous operation has finished. For example, when a request-level module calls the IHttpResponse::WriteEntityChunks method and specifies asynchronous completion, IIS will call the module's OnAsyncCompletion method when the operation is complete.

When IIS calls the OnAsyncCompletion method, it will specify the notification type in the dwNotification parameter, and it will indicate whether the notification was for an event or post-event by using the fPostNotification parameter. IIS also provides an IHttpCompletionInfo interface that is pointed to by the pCompletionInfo parameter. You can use this interface to retrieve additional information about the asynchronous completion.

Example

The following code example demonstrates how to create an HTTP module that performs the following tasks:

  1. The module registers for the RQ_BEGIN_REQUEST and RQ_MAP_REQUEST_HANDLER notifications.

  2. The module creates a CHttpModule class that contains OnBeginRequest, OnMapRequestHandler, and OnAsyncCompletion methods.

  3. When a Web client requests a URL, IIS calls the module's OnBeginRequest method. This method performs the following tasks:

    1. Clears the existing response buffer and sets the MIME type for the response.

    2. Creates an example string and returns that to the Web client asynchronously.

    3. Tests for an error or asynchronous completion. If asynchronous completion is pending, the module returns a pending notification status to the integrated request-processing pipeline.

  4. IIS calls the module's OnMapRequestHandler method. This method performs the following tasks:

    1. Flushes the current response buffer to the Web client.

    2. Tests for an error or asynchronous completion. If asynchronous completion is pending, the module returns a pending notification status to the pipeline.

  5. If asynchronous completion is required, IIS calls the module's OnAsyncCompletion method. This method performs the following tasks:

    1. Tests for a valid IHttpCompletionInfo interface. If a valid IHttpCompletionInfo interface was passed, the method calls the GetCompletionBytes and GetCompletionStatus methods, respectively, to retrieve the completed bytes and return the status for the asynchronous operation.

    2. Creates strings that contain the completion information and writes the information as an event to the application log of the Event Viewer.

  6. The module removes the CHttpModule class from memory and then exits.

Your module must export the RegisterModule function. You can export this function by creating a module definition (.def) file for your project, or you can compile the module by using the /EXPORT:RegisterModule switch. For more information, see Walkthrough: Creating a Request-Level HTTP Module By Using Native Code.

You can optionally compile the code by using the __stdcall (/Gz) calling convention instead of explicitly declaring the calling convention for each function.

Requirements

Type

Description

Client

  • IIS 7.0 on Windows Vista

  • IIS 7.5 on Windows 7

  • IIS 8.0 on Windows 8

  • IIS 10.0 on Windows 10

Server

  • IIS 7.0 on Windows Server 2008

  • IIS 7.5 on Windows Server 2008 R2

  • IIS 8.0 on Windows Server 2012

  • IIS 8.5 on Windows Server 2012 R2

  • IIS 10.0 on Windows Server 2016 Technical Preview

Product

  • IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0

  • IIS Express 7.5, IIS Express 8.0, IIS Express 10.0

Header

Httpserv.h

Show: