IGlobalTraceEventProvider::GetCurrentHttpRequestCoNtext 方法
擷取要求特定之追蹤事件的 HTTP 內容。
語法
virtual HRESULT GetCurrentHttpRequestContext(
IHttpContext** ppHttpContext
) = 0;
參數
ppHttpContext
介面位址的 IHttpContext
指標,否則為 Null。
傳回值
HRESULT
。 可能的值包括 (但不限於) 下表中的這些值。
值 | 定義 |
---|---|
S_OK | 表示作業成功。 |
ERROR_NOT_SUPPORTED | 表示不支援 方法。 |
備註
註冊GL_TRACE_EVENT事件種類的CGlobalModule衍生類別會接收IGlobalTraceEventProvider指標做為CGlobalModule::OnGlobalTraceEvent純 virtual
方法的參數。 然後,您可以在該 IGlobalTraceEventProvider
指標上呼叫 方法, GetCurrentHttpRequestContext
以擷取IHttpCoNtext指標。
的其中一個可能用途 GetCurrentHttpRequestContext
是提供事件的自訂緩衝處理。
GetCurrentHttpRequestContext
行為取決於實作。 您應該使用下列資訊作為指導方針,但在所有案例中可能都不正確:
提供 HTTP 追蹤事件的類別會宣告
private``IHttpContext
指標成員變數。 這個變數會在建構期間初始化為有效的IHttpContext
指標。 當您呼叫GetCurrentHttpRequestContext
時,會將 dereferencedppHttpContext
參數設定為這個變數,並傳回S_OK。提供全域追蹤事件的類別不會修改
ppHttpContext
參數,並立即傳回ERROR_NOT_SUPPORTED。
實作者的注意事項
IGlobalTraceEventProvider
實作者負責使用此資料的記憶體管理;因此,當不再需要動態記憶體配置時, IGlobalTraceEventProvider
使用動態記憶體配置的實作必須釋放或呼叫 delete
IHttpContext
指標。
來電者的注意事項
IGlobalTraceEventProvider
實作者負責使用此資料的記憶體管理;因此,當不再需要此資料時, IGlobalTraceEventProvider
用戶端不得釋放或呼叫 delete
傳 IHttpContext
回的指標。
範例
下列程式碼範例示範如何建立全域模組,以接聽 GL_TRACE_EVENT 事件,並宣告和初始化篩選事件的 HTTP_TRACE_CONFIGURATION 結構。 然後,模組會 IHttpContext
呼叫 GetCurrentHttpRequestContext
方法來擷取指標。
#pragma warning( disable : 4290 )
#pragma warning( disable : 4530 )
#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <tchar.h>
#include <initguid.h>
#include <httptrace.h>
#include <httpserv.h>
#include <httpcach.h>
// The CGlobalTraceModule class creates the CGlobalModule
// class and registers for GL_TRACE_EVENT events.
class CGlobalContainerModule : public CGlobalModule
{
public:
// Creates the destructor for the
// CGlobalTraceModule class.
virtual ~CGlobalContainerModule()
{
}
// The RegisterGlobalModule method creates and registers
// a new CGlobalTraceModule for GL_TRACE_EVENT events.
// dwServerVersion: the current server version.
// pModuleInfo: the current IHttpModuleRegistrationInfo pointer.
// pGlobalInfo: the current IHttpServer pointer.
// return: ERROR_NOT_ENOUGH_MEMORY if the heap is out of
// memory; otherwise, the value from the call to the
// SetGlobalNotifications method on the pModuleInfo pointer.
static HRESULT RegisterGlobalModule
(
DWORD dwServerVersion,
IHttpModuleRegistrationInfo* pModuleInfo,
IHttpServer* pGlobalInfo
)
{
// The IHttpModuleRegistrationInfo
// pointermust not be NULL.
if (NULL == pModuleInfo)
{
return E_INVALIDARG;
}
// Get the HTTP_MODULE_ID from the
// IHttpModuleRegistrationInfo pointer.
HTTP_MODULE_ID moduleId =
pModuleInfo->GetId();
// The HTTP_MODULE_ID pointer
// must not be NULL.
if (NULL == moduleId)
{
return E_INVALIDARG;
}
// Create a new CGlobalContainerModule pointer
// using the HTTP_MODULE_ID from the
// IHttpModuleRegistrationInfo pointer.
CGlobalContainerModule* containerModule =
new CGlobalContainerModule(moduleId);
// Return an out-of-memory error if the containerModule
// is NULL after the call to the new operator.
if (NULL == containerModule)
{
return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
}
// Attempt to set global notification
// for an GL_TRACE_EVENT event by using
// the traceModule as a listener.
HRESULT hr = pModuleInfo->SetGlobalNotifications
(containerModule, GL_TRACE_EVENT);
// Return the HRESULT from the call to
// the SetGlobalNotifications method.
return hr;
}
// The OnGlobalTraceEvent method is the callback
// method for GL_TRACE_EVENT events in the pipeline.
// pProvider: the IGlobalTraceEventProvider pointer.
// return: GL_NOTIFICATION_CONTINUE.
virtual
GLOBAL_NOTIFICATION_STATUS
OnGlobalTraceEvent
(
IN IGlobalTraceEventProvider* pProvider
)
{
// If the IGlobalTraceEventProvider pointer
// is NULL, return GL_NOTIFICATION_CONTINUE.
if (NULL == pProvider)
{
return GL_NOTIFICATION_CONTINUE;
}
// Declare an IHttpContext pointer.
IHttpContext* httpContext = NULL;
// Declare an HRESULT and initialize
// the HRESULT to E_FAIL.
HRESULT hr = E_FAIL;
// Call the GetCurrentHttpRequestContext
// method on the IGlobalTraceEventProvider
// pointer.
hr = pProvider->GetCurrentHttpRequestContext(&httpContext);
// Return GL_NOTIFICATION_CONTINUE.
return GL_NOTIFICATION_CONTINUE;
}
// The Terminate method is required for
// non-abstract CGlobalTraceModule classes.
// This method calls delete on this.
virtual VOID Terminate(VOID)
{
delete this;
}
// Creates the constructor for the CGlobalTraceModule
// class. This constructor initializes the CEventWriter
// to write to the application event log.
// moduleId: the current module identifier.
CGlobalContainerModule(HTTP_MODULE_ID moduleId)
{
m_moduleId = moduleId;
}
private:
// Specify the HTTP_MODULE_ID
// for this module.
HTTP_MODULE_ID m_moduleId;
};
// The RegisterModule method is the
// main entry point for the DLL.
// dwServerVersion: the current server version.
// pModuleInfo: the current
// IHttpModuleRegistrationInfo pointer.
// pGlobalInfo: the current IHttpServer pointer.
// return: the value returned by calling the
// CGlobalContainerModule::RegisterGlobalModule
// method.
HRESULT
__stdcall
RegisterModule(
DWORD dwServerVersion,
IHttpModuleRegistrationInfo* pModuleInfo,
IHttpServer* pGlobalInfo
)
{
// Call the static method for initialization.
return CGlobalContainerModule::RegisterGlobalModule
(dwServerVersion,
pModuleInfo,
pGlobalInfo);
}
您的模組必須匯出 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 |