IHttpModuleContextContainer::GetModuleContext 메서드
컨텍스트 컨테이너에서 저장된 컨텍스트를 반환합니다.
구문
virtual IHttpStoredContext* GetModuleContext(
IN HTTP_MODULE_ID moduleId
) = 0;
매개 변수
moduleId
[IN] 포인터입니다 HTTP_MODULE_ID
.
참고
HTTP_MODULE_ID
는 포인터의 형식 정의입니다 void
.
반환 값
IHttpStoredContext에 대한 포인터입니다. 그렇지 않으면 NULL입니다.
설명
CGlobalModule 또는 CHttpModule 포인터는 Httpserv.h 헤더 파일에 정의된 다양한 이벤트에 등록됩니다. 자세한 내용은 요청 처리 상수를 참조하세요. 이러한 클래스의 virtual
메서드를 통해 메서드를 구현하는 다양한 인터페이스에서 IHttpModuleContextContainer 포인터를 GetModuleContextContainer
검색할 수 있습니다.
인터페이스를 구현하는 사용자 지정 클래스를 IHttpStoredContext
정의한 다음 연산자를 호출하여 이 IHttpStoredContext
클래스 구현자에 대한 포인터를 new
만들 수 있습니다. 그런 다음 SetModuleContextGetModuleContext
및 메서드를 IHttpModuleContextContainer
각각 호출하여 포인터에 이 포인터를 추가하고 검색할 수 있습니다.
포인터가 IHttpStoredContext
더 이상 필요하지 않으면 IHttpStoredContext::CleanupStoredContext 메서드가 내부적으로 호출됩니다. 여기서 인터페이스 메서드의 IHttpStoredContext
구현자는 일반적으로 를 호출 delete``this
해야 합니다.
구현자에 대한 참고 사항
IHttpModuleContextContainer 구현자는 이 데이터를 사용하여 메모리 관리를 담당합니다. 따라서 IHttpModuleContextContainer
동적 메모리 할당을 사용하는 구현자는 더 이상 필요하지 않은 경우 포인터를 IHttpStoredContext
해제하거나 를 호출 delete
해야 합니다. 정리가 필요한 경우 IHttpStoredContext::CleanupStoredContext 메서드를 호출할 수 있습니다.
호출자 참고 사항
IHttpModuleContextContainer
구현자는 이 데이터를 사용하여 메모리 관리를 담당합니다. 따라서 IHttpModuleContextContainer
클라이언트는 이 데이터가 더 이상 필요하지 않을 때 반환 IHttpStoredContext
된 포인터를 해제하거나 호출 delete
하지 않아야 합니다.
예제
다음 코드 예제에서는 GL_TRACE_EVENT 이벤트를 수신 대기한 다음 메서드를 호출 GetModuleContext
하여 포인터를 검색하는 전역 모듈을 IHttpStoredContext
만드는 방법을 보여 줍니다.
#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);
// If the GetCurrentHttpRequestContext
// method failed, or the IHttpContext
// pointer is NULL, return GL_NOTIFICATION_CONTINUE.
if (FAILED(hr) || (NULL == httpContext))
{
return GL_NOTIFICATION_CONTINUE;
}
// Get the IHttpModuleContextContainer
// pointer from the IHttpContext pointer.
IHttpModuleContextContainer* container =
httpContext->GetModuleContextContainer();
// If the IHttpModuleContextContainer is
// NULL, return GL_NOTIFICATION_CONTINUE.
if (NULL == container)
{
return GL_NOTIFICATION_CONTINUE;
}
// Get the IHttpStoredContext pointer
// from the IHttpModuleContextContainer
// pointer.
IHttpStoredContext* storedContext =
container->GetModuleContext(m_moduleId);
// 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;
}
protected:
// 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);
}
요구 사항
형식 | Description |
---|---|
클라이언트 | - 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 |
참고 항목
IHttpModuleContextContainer 인터페이스
IHttpModuleContextContainer::SetModuleContext 메서드