IHttpContext::GetExecuteFlags 方法

检索当前上下文的执行标志。

语法

virtual DWORD GetExecuteFlags(  
   VOID  
) const = 0;  

参数

此方法不采用参数。

返回值

包含 DWORD 执行标志的 。

备注

方法 GetExecuteFlags 检索当前上下文的执行标志。 下表列出了这些标志的可能值。

说明
EXECUTE_FLAG_NO_HEADERS 禁止显示子请求的 HTTP 标头。
EXECUTE_FLAG_IGNORE_CURRENT_INTERCEPTOR 忽略此请求链的当前脚本映射处理程序。
EXECUTE_FLAG_IGNORE_APPPOOL 即使子请求不在同一应用程序池中,也执行请求。
EXECUTE_FLAG_DISABLE_CUSTOM_ERROR 禁用子请求的自定义错误。
EXECUTE_FLAG_SAME_URL 子请求的 URL 与父请求相同。
EXECUTE_FLAG_BUFFER_RESPONSE 不刷新子响应;返回对父请求的响应。
EXECUTE_FLAG_HTTP_CACHE_ELIGIBLE 子响应仍可通过Http.sys进行缓存。

示例

下面的代码示例演示如何创建执行以下任务的 HTTP 模块:

  1. 模块注册 RQ_SEND_RESPONSE 通知。

  2. 该模块创建包含 OnSendResponse 方法的 CHttpModule 类。

  3. 当 Web 客户端请求 URL 时,IIS 会调用模块的 OnSendResponse 方法。 此方法执行以下任务:

    1. 清除现有响应缓冲区并设置响应的 MIME 类型。

    2. 使用 GetExecuteFlags 方法检索当前上下文的执行标志。

    3. 测试单个执行标志,并将状态返回到 Web 客户端。

  4. 该模块从内存中删除 CHttpModule 类,然后退出。

#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <httpserv.h>

// Create the module class.
class MyHttpModule : public CHttpModule
{
public:
    REQUEST_NOTIFICATION_STATUS
    OnSendResponse(
        IN IHttpContext * pHttpContext,
        IN ISendResponseProvider * pProvider
    )
    {
        UNREFERENCED_PARAMETER( pProvider );
        
        // Clear the existing response.
        pHttpContext->GetResponse()->Clear();
        // Set the MIME type to plain text.
        pHttpContext->GetResponse()->SetHeader(
            HttpHeaderContentType,"text/plain",
            (USHORT)strlen("text/plain"),TRUE);

        WriteResponseMessage(pHttpContext,"Execute Flags:\n");

        // Retrieve the execution flags.
        DWORD dwExecuteFlags = pHttpContext->GetExecuteFlags();

        // Test for any flags.
        if (dwExecuteFlags == 0)
        {
            // Return a generic status if no flags are set.
            WriteResponseMessage(pHttpContext,"N/A\n");
        }
        // Test for individual flags and return them to a Web client.
        else
        {
            if (dwExecuteFlags & EXECUTE_FLAG_NO_HEADERS)
                WriteResponseMessage(pHttpContext,
                "EXECUTE_FLAG_NO_HEADERS\n");
            if (dwExecuteFlags & EXECUTE_FLAG_IGNORE_CURRENT_INTERCEPTOR)
                WriteResponseMessage(pHttpContext,
                "EXECUTE_FLAG_IGNORE_CURRENT_INTERCEPTOR\n");
            if (dwExecuteFlags & EXECUTE_FLAG_IGNORE_APPPOOL)
                WriteResponseMessage(pHttpContext,
                "EXECUTE_FLAG_IGNORE_APPPOOL\n");
            if (dwExecuteFlags & EXECUTE_FLAG_DISABLE_CUSTOM_ERROR)
                WriteResponseMessage(pHttpContext,
                "EXECUTE_FLAG_DISABLE_CUSTOM_ERROR\n");
            if (dwExecuteFlags & EXECUTE_FLAG_SAME_URL)
                WriteResponseMessage(pHttpContext,
                "EXECUTE_FLAG_SAME_URL\n");
            if (dwExecuteFlags & EXECUTE_FLAG_BUFFER_RESPONSE)
                WriteResponseMessage(pHttpContext,
                "EXECUTE_FLAG_BUFFER_RESPONSE\n");
            if (dwExecuteFlags & EXECUTE_FLAG_HTTP_CACHE_ELIGIBLE)
                WriteResponseMessage(pHttpContext,
                "EXECUTE_FLAG_HTTP_CACHE_ELIGIBLE\n");
        }

        // Return processing to the pipeline.
        return RQ_NOTIFICATION_FINISH_REQUEST;
    }

private:

    // Create a utility method that inserts a string value into the response.
    HRESULT WriteResponseMessage(
        IHttpContext * pHttpContext,
        PCSTR pszBuffer
    )
    {
        // Create an HRESULT to receive return values from methods.
        HRESULT hr;
        
        // Create a data chunk.
        HTTP_DATA_CHUNK dataChunk;
        // Set the chunk to a chunk in memory.
        dataChunk.DataChunkType = HttpDataChunkFromMemory;
        // Buffer for bytes written of data chunk.
        DWORD cbSent;

        // Set the chunk to the buffer.
        dataChunk.FromMemory.pBuffer =
            (PVOID) pszBuffer;
        // Set the chunk size to the buffer size.
        dataChunk.FromMemory.BufferLength =
            (USHORT) strlen(pszBuffer);
        // Insert the data chunk into the response.
        hr = pHttpContext->GetResponse()->WriteEntityChunks(
            &dataChunk,1,FALSE,TRUE,&cbSent);
        // Test for an error.
        if (FAILED(hr))
        {
            // Return the error status.
            return hr;
        }

        // Return a success status.
        return S_OK;
    }
};

// Create the module's class factory.
class MyHttpModuleFactory : public IHttpModuleFactory
{
public:
    HRESULT
    GetHttpModule(
        OUT CHttpModule ** ppModule, 
        IN IModuleAllocator * pAllocator
    )
    {
        UNREFERENCED_PARAMETER( pAllocator );

        // Create a new instance.
        MyHttpModule * pModule = new MyHttpModule;

        // Test for an error.
        if (!pModule)
        {
            // Return an error if we cannot create the instance.
            return HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY );
        }
        else
        {
            // Return a pointer to the module.
            *ppModule = pModule;
            pModule = NULL;
            // Return a success status.
            return S_OK;
        }            
    }

    void Terminate()
    {
        // Remove the class from memory.
        delete this;
    }
};

// Create the module's exported registration function.
HRESULT
__stdcall
RegisterModule(
    DWORD dwServerVersion,
    IHttpModuleRegistrationInfo * pModuleInfo,
    IHttpServer * pGlobalInfo
)
{
    UNREFERENCED_PARAMETER( dwServerVersion );
    UNREFERENCED_PARAMETER( pGlobalInfo );

    return pModuleInfo->SetRequestNotifications(
        new MyHttpModuleFactory,
        RQ_SEND_RESPONSE,
        0
    );
}

模块必须导出 RegisterModule 函数。 可以通过为项目创建模块定义 (.def) 文件导出此函数,也可以使用 开关编译模块 /EXPORT:RegisterModule 。 有关详细信息,请参阅 演练:使用本机代码创建Request-Level HTTP 模块

可以选择使用调用约定编译代码, __stdcall (/Gz) 而不是为每个函数显式声明调用约定。

要求

类型 说明
客户端 - Windows Vista 上的 IIS 7.0
- Windows 7 上的 IIS 7.5
- Windows 8 上的 IIS 8.0
- Windows 10 上的 IIS 10.0
服务器 - Windows Server 2008 上的 IIS 7.0
- Windows Server 2008 R2 上的 IIS 7.5
- Windows Server 2012 上的 IIS 8.0
- Windows Server 2012 R2 上的 IIS 8.5
- Windows Server 2016 上的 IIS 10.0
产品 - 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

另请参阅

IHttpContext 接口
IHttpContext::ExecuteRequest 方法