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;

fAsync

[IN] Always true (specifies asynchronous execution).

pHttpContext

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

dwExecuteFlags

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

pHttpUser

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

pfCompletionExpected

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

Value

Description

S_OK

Indicates that the operation was successful.

ERROR_NOT_SUPPORTED

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

ERROR_STACK_OVERFLOW

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.

System_CAPS_importantImportant

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.

System_CAPS_noteNote

   The limit for recursive child requests is 10.

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

System_CAPS_importantImportant

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.

Value

Description

EXECUTE_FLAG_NO_HEADERS

Suppress the HTTP headers for the child request.

EXECUTE_FLAG_IGNORE_CURRENT_INTERCEPTOR

Ignore the current script map handler for this request chain.

EXECUTE_FLAG_IGNORE_APPPOOL

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

EXECUTE_FLAG_DISABLE_CUSTOM_ERROR

Disable custom errors for the child request.

EXECUTE_FLAG_SAME_URL

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

System_CAPS_noteNote

Script map handlers use this flag to forward execution.

EXECUTE_FLAG_BUFFER_RESPONSE

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

EXECUTE_FLAG_HTTP_CACHE_ELIGIBLE

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

System_CAPS_noteNote

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.

Example

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.

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: