IHttpContext::ExecuteRequest Method

IIS 7.0

Executes a child request.

virtual HRESULT ExecuteRequest(
   IN BOOL fAsync,
   IN IHttpContext* pHttpContext,
   IN DWORD dwExecuteFlags,
   IN IHttpUser* pHttpUser,
   OUT BOOL* pfCompletionExpected = NULL
) = 0;


[IN] Always true (specifies asynchronous execution).


[IN] A pointer to the child IHttpContext to execute.


[IN] A DWORD that contains the request execution flags.


[IN] A pointer to an IHttpUser for the request. (Optional)


[OUT] true if asynchronous completion is still pending; otherwise, false. (Optional)

An HRESULT. Possible values include, but are not limited to, those in the following table.




Indicates that the operation was successful.


Indicates that the request is not supported (for example, fAsync is set to false or the child request was not cloned from the parent request).


Indicates that request exceeds the limit for recursive child requests.

The ExecuteRequest method executes the child request that is specified by the IHttpContext interface in the pHttpContext parameter. You must create this request context by using the IHttpContext::CloneContext method.


Attempting to execute a child request that was not cloned by the parent request will return ERROR_NOT_SUPPORTED.

Each child context can be executed only once, although child requests can be nested recursively.


   The limit for recursive child requests is 10.

The ExecuteRequest method supports only asynchronous operation, which prevents exhausting the thread pool.


Attempting to execute a synchronous child request will return ERROR_NOT_SUPPORTED.

You can control the execution behavior for the child request by specifying execution flags in dwExecuteFlags. The following table lists the possible values for these flags.




Suppress the HTTP headers for the child request.


Ignore the current script map handler for this request chain.


Execute the request even if the child request is not in the same application pool.


Disable custom errors for the child request.


The URL for the child request is the same as the parent request.


Script map handlers use this flag to forward execution.


Do not flush the child response; return the response to the parent request.


The child response is still eligible for caching by Http.sys.


Caching is disabled by default when a child request is executed.

If you specify an IHttpUser interface for pHttpUser, authentication will be skipped for the child request.


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

  1. The module registers for the RQ_MAP_PATH notification.

  2. The module creates a CHttpModule class that contains OnMapPath and OnAsyncCompletion methods.

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

    1. Tests to see whether the URL for the current request matches two specific URLs at the root of the Web site. If the URL matches either of the specified URLs, the module uses the IHttpContext::CloneContext method to create a clone of the current request.

    2. Calls the clone's IHttpRequest::SetUrl method to set the URL for the clone to /example/default.aspx.

    3. Calls the ExecuteRequest method to execute the child request.

    4. Tests for asynchronous completion. If asynchronous completion is pending, the module returns processing to the integrated request-processing pipeline. If not, the module releases the cloned context.

  4. If asynchronous completion is required, IIS calls the module's OnAsyncCompletion method. This method releases the cloned context.

  5. 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.





  • IIS 7.0 on Windows Vista

  • IIS 7.5 on Windows 7

  • IIS 8.0 on Windows 8

  • IIS 10.0 on Windows 10


  • 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


  • 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