IGlobalTraceEventProvider::GetCurrentHttpRequestContext 메서드

요청별 추적 이벤트에 대한 HTTP 컨텍스트를 검색합니다.

구문

virtual HRESULT GetCurrentHttpRequestContext(  
   IHttpContext** ppHttpContext  
) = 0;  

매개 변수

ppHttpContext
인터페이스의 주소에 대한 포인터입니다 IHttpContext . 그렇지 않으면 NULL입니다.

반환 값

HRESULT입니다. 가능한 값에는 다음 표에 있는 값이 포함되지만, 이에 국한되는 것은 아닙니다.

정의
S_OK 작업이 성공했음을 나타냅니다.
ERROR_NOT_SUPPORTED 메서드가 지원되지 않음을 나타냅니다.

설명

GL_TRACE_EVENT 이벤트 형식에 등록하는 CGlobalModule 파생 클래스는 CGlobalModule::OnGlobalTraceEvent pure virtual 메서드의 매개 변수로 IGlobalTraceEventProvider 포인터를 받습니다. 그런 다음 해당 포인터에서 메서드를 호출하여 IHttpContext 포인터를 GetCurrentHttpRequestContext 검색할 IGlobalTraceEventProvider 수 있습니다.

한 가지 가능한 용도 GetCurrentHttpRequestContext 는 이벤트의 사용자 지정 버퍼링을 제공하는 것입니다.

GetCurrentHttpRequestContext 동작은 구현에 따라 달라집니다. 다음 정보를 지침으로 사용해야 하지만 모든 시나리오에서 올바르지 않을 수 있습니다.

  • HTTP 추적 이벤트를 제공하는 클래스는 포인터 멤버 변수를 private``IHttpContext 선언합니다. 이 변수는 생성 중에 유효한 IHttpContext 포인터로 초기화됩니다. 를 호출 GetCurrentHttpRequestContext하면 역참조 매개 ppHttpContext 변수가 이 변수로 설정되고 S_OK 반환됩니다.

  • 전역 추적 이벤트를 제공하는 클래스는 매개 변수를 ppHttpContext 수정하지 않고 즉시 ERROR_NOT_SUPPORTED 반환합니다.

구현자에 대한 참고 사항

IGlobalTraceEventProvider구현자는 이 데이터를 사용하여 메모리 관리를 담당합니다. 따라서 IGlobalTraceEventProvider 동적 메모리 할당을 사용하는 구현자는 더 이상 필요하지 않은 경우 포인터를 IHttpContext 해제하거나 를 호출 delete 해야 합니다.

호출자 참고 사항

IGlobalTraceEventProvider구현자는 이 데이터를 사용하여 메모리 관리를 담당합니다. 따라서 IGlobalTraceEventProvider 클라이언트는 이 데이터가 더 이상 필요하지 않을 때 반환 IHttpContext 된 포인터를 해제하거나 를 호출 delete 해서는 안 됩니다.

예제

다음 코드 예제에서는 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) 코드를 컴파일할 수 있습니다.

요구 사항

형식 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

참고 항목

IGlobalTraceEventProvider 인터페이스