| title | IHttpContext::ExecuteRequest Method |
|---|---|
| description | IHttpContext::ExecuteRequest Method the I H t t p Context Execute Request Method executes a child request. |
| ms.date | 10/07/2016 |
| ms.assetid | b52b477c-0e04-f8f1-4607-13ba5212f91e |
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.
Important
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.
Note
The limit for recursive child requests is 10.
The ExecuteRequest method supports only asynchronous operation, which prevents exhausting the thread pool.
Important
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. Note: 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. Note: 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:
-
The module registers for the RQ_MAP_PATH notification.
-
The module creates a CHttpModule class that contains OnMapPath and OnAsyncCompletion methods.
-
When a Web client requests a URL, IIS calls the module's
OnMapPathmethod. This method performs the following tasks:-
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::CloneContextmethod to create a clone of the current request. -
Calls the clone's
IHttpRequest::SetUrlmethod to set the URL for the clone to /example/default.aspx. -
Calls the
ExecuteRequestmethod to execute the child request. -
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.
-
-
If asynchronous completion is required, IIS calls the module's
OnAsyncCompletionmethod. This method releases the cloned context. -
The module removes the
CHttpModuleclass from memory and then exits.
[!code-cppIHttpContextExecuteRequest#1]
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.
| Type | Description |
|---|---|
| Client | - IIS 7.0 on [!INCLUDEwinvista] - IIS 7.5 on Windows 7 - IIS 8.0 on Windows 8 - IIS 10.0 on Windows 10 |
| Server | - IIS 7.0 on [!INCLUDEwinsrv2008] - 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 |
| Product | - IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0 - [!INCLUDEiisexp75], [!INCLUDEiisexp80], [!INCLUDEiisexp100] |
| Header | Httpserv.h |
IHttpContext Interface
IHttpContext::CloneContext Method
IHttpContext::GetParentContext Method
IHttpContext::ReleaseClonedContext Method