Nota
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
Recupera el contexto HTTP para los eventos de seguimiento que son específicos de la solicitud.
Sintaxis
virtual HRESULT GetCurrentHttpRequestContext(
IHttpContext** ppHttpContext
) = 0;
Parámetros
ppHttpContext
Puntero a la dirección de una IHttpContext
interfaz; de lo contrario, NULL.
Valor devuelto
Una clase HRESULT
. Entre los valores posibles se incluyen los que se indican en la tabla siguiente, entre otros.
Value | Definición |
---|---|
S_OK | Indica que la operación se realizó correctamente. |
ERROR_NOT_SUPPORTED | Indica que no se admite el método . |
Comentarios
Las clases derivadas de CGlobalModule que se registran para GL_TRACE_EVENT tipos de eventos reciben un puntero IGlobalTraceEventProvider como parámetro en el método puro virtual
CGlobalModule::OnGlobalTraceEvent. A continuación, puede recuperar un puntero IHttpContext llamando al GetCurrentHttpRequestContext
método en ese IGlobalTraceEventProvider
puntero.
Un posible uso para GetCurrentHttpRequestContext
es proporcionar almacenamiento en búfer personalizado de eventos.
GetCurrentHttpRequestContext
el comportamiento depende de la implementación. Debe usar la siguiente información como guía, pero puede que no sea correcta en todos los escenarios:
Las clases que proporcionan eventos de seguimiento HTTP declaran una
private``IHttpContext
variable miembro de puntero. Esta variable se inicializa durante la construcción en un puntero válidoIHttpContext
. Cuando se llama aGetCurrentHttpRequestContext
, el parámetro desreferenciadoppHttpContext
se establece en esta variable y se devuelve S_OK.Las clases que proporcionan eventos de seguimiento global no modifican el
ppHttpContext
parámetro y devuelven ERROR_NOT_SUPPORTED inmediatamente.
Notas para los implementadores
IGlobalTraceEventProvider
los implementadores son responsables de la administración de memoria con estos datos; por lo tanto, IGlobalTraceEventProvider
los implementadores que usan la asignación de memoria dinámica deben liberarse o llamar delete
al IHttpContext
puntero cuando ya no sea necesario.
Notas para autores de la llamada
IGlobalTraceEventProvider
los implementadores son responsables de la administración de memoria con estos datos; por lo tanto, los IGlobalTraceEventProvider
clientes no deben liberar ni llamar delete
al puntero devuelto IHttpContext
cuando estos datos ya no son necesarios.
Ejemplo
En el ejemplo de código siguiente se muestra cómo crear un módulo global que escucha eventos de GL_TRACE_EVENT y declara e inicializa una estructura de HTTP_TRACE_CONFIGURATION que filtra los eventos. A continuación, el módulo recupera el IHttpContext
puntero llamando al GetCurrentHttpRequestContext
método .
#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);
}
El módulo debe exportar la función RegisterModule . Puede exportar esta función mediante la creación de un archivo de definición de módulo (.def) para el proyecto, o bien puede compilar el módulo mediante el /EXPORT:RegisterModule
modificador . Para obtener más información, vea Tutorial: Creación de un módulo HTTP de Request-Level mediante código nativo.
Opcionalmente, puede compilar el código mediante la __stdcall (/Gz)
convención de llamada en lugar de declarar explícitamente la convención de llamada para cada función.
Requisitos
Tipo | Descripción |
---|---|
Remoto | - IIS 7.0 en Windows Vista - IIS 7.5 en Windows 7 - IIS 8.0 en Windows 8 - IIS 10.0 en Windows 10 |
Servidor | - IIS 7.0 en Windows Server 2008 - IIS 7.5 en Windows Server 2008 R2 - IIS 8.0 en Windows Server 2012 - IIS 8.5 en Windows Server 2012 R2 - IIS 10.0 en Windows Server 2016 |
Producto | - 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 |
Encabezado | Httpserv.h |