擷取目前內容的執行旗標。
語法
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 模組:
模組會註冊 RQ_SEND_RESPONSE 通知。
此模組會建立包含OnSendResponse方法的CHttpModule類別。
當 Web 用戶端要求 URL 時,IIS 會呼叫模組
OnSendResponse的 方法。 這個方法會執行下列工作:清除現有的回應緩衝區,並設定回應的 MIME 類型。
使用
GetExecuteFlags方法擷取目前內容的執行旗標。測試個別執行旗標,並將狀態傳回給 Web 用戶端。
模組會
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) 而不是明確宣告每個函式的呼叫慣例。
規格需求
| 類型 | 描述 |
|---|---|
| Client | - 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 |
| 標頭 | Httpserv.h |