CGlobalModule::OnGlobalCustomNotification (Método)
Representa el método que controlará un GlobalCustomNotification
evento, que se produce cuando un módulo genera una notificación definida por el usuario.
Sintaxis
virtual GLOBAL_NOTIFICATION_STATUS OnGlobalCustomNotification(
IN ICustomNotificationProvider* pProvider
);
Parámetros
pProvider
[IN] Puntero a una interfaz ICustomNotificationProvider .
Valor devuelto
Valor de GLOBAL_NOTIFICATION_STATUS .
Comentarios
Cuando se ha registrado un módulo global para la notificación de eventos de GL_CUSTOM_NOTIFICATION , IIS llamará al método del OnGlobalCustomNotification
módulo si se genera una notificación personalizada global (por ejemplo, si un módulo llama a IHttpServer::NotifyCustomNotification).
Nota:
Los módulos globales se pueden registrar para la GlobalCustomNotification
notificación de eventos registrando para GL_CUSTOM_NOTIFICATION
en la función RegisterModule del módulo.
Ejemplo
En el ejemplo de código siguiente se muestra cómo crear un módulo HTTP que realice las tareas siguientes:
Se registra para la GL_PRE_BEGIN_REQUEST y
GL_CUSTOM_NOTIFICATION
las notificaciones.Crea una clase CGlobalModule que contiene métodos OnGlobalPreBeginRequest y OnGlobalCustomNotification .
El
OnGlobalPreBeginRequest
método escribe un evento en el Visor de eventos que especifica la notificación actual. A continuación, el método crea una instancia de unaICustomNotificationProvider
interfaz y genera la notificación personalizada mediante elNotifyCustomNotification
método .El
OnGlobalCustomNotification
método usa el método ICustomNotificationProvider::QueryNotificationType para recuperar el identificador único de la notificación personalizada. Si el identificador único coincide, elOnGlobalCustomNotification
método escribe un evento en el Visor de eventos que especifica que se generó la notificación personalizada.
Quita la
CGlobalModule
clase de la memoria y, a continuación, se cierra.
#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <httpserv.h>
// Define the unique notification indentifier.
#define MY_CUSTOM_NOTIFICATION L"MyCustomNotification"
// Create a pointer for the global server interface.
IHttpServer * g_pHttpServer = NULL;
// Create the custom notification class.
class MyCustomProvider : public ICustomNotificationProvider
{
public:
// Create the method that will identify the custom notification.
PCWSTR QueryNotificationType(VOID)
{
// Return the unique identifier string for the custom notification.
return MY_CUSTOM_NOTIFICATION;
}
// Create the method that will process errors.
VOID SetErrorStatus(HRESULT hrError)
{
return;
}
};
// Create the module's global class.
class MyGlobalModule : public CGlobalModule
{
private:
// Create a handle for the Event Viewer.
HANDLE m_hEventLog;
// Create a pointer for the custom notification.
MyCustomProvider * m_pCustomProvider;
public:
MyGlobalModule()
{
// Open the global handle to the Event Viewer.
m_hEventLog = RegisterEventSource( NULL,"IISADMIN" );
// Initialize the pointer for the custom notification to NULL.
m_pCustomProvider = NULL;
}
~MyGlobalModule()
{
// Test whether the handle for the Event Viewer is open.
if (NULL != m_hEventLog)
{
// Close the handle to the event viewer.
DeregisterEventSource( m_hEventLog );
m_hEventLog = NULL;
}
// Test whether the pointer for the custom notification is valid.
if (NULL != m_pCustomProvider)
{
// Remove the custom notification from memory.
delete m_pCustomProvider;
m_pCustomProvider = NULL;
}
}
GLOBAL_NOTIFICATION_STATUS
OnGlobalPreBeginRequest(
IN IPreBeginRequestProvider * pProvider
)
{
// Create an array of strings.
LPCSTR szBuffer[2] = {"MyGlobalModule","OnGlobalPreBeginRequest"};
// Write the strings to the Event Viewer.
WriteEventViewerLog(szBuffer,2);
// Create the custom notification provider class.
MyCustomProvider * m_pCustomProvider = new MyCustomProvider;
// Test if the server and notification pointers are valid.
if ((NULL != m_pCustomProvider) && (NULL != g_pHttpServer))
{
// Raise the custom notification.
BOOL fCompletionExpected = TRUE;
g_pHttpServer->NotifyCustomNotification(m_pCustomProvider);
}
// Return processing to the pipeline.
return GL_NOTIFICATION_CONTINUE;
}
GLOBAL_NOTIFICATION_STATUS
OnGlobalCustomNotification(
IN ICustomNotificationProvider * pProvider
)
{
// Retrieve the custom notification type;
PCWSTR pNotificationType = pProvider->QueryNotificationType();
// Test if the custom notification is correct.
if (0 == wcscmp(pNotificationType,MY_CUSTOM_NOTIFICATION))
{
// Create an array of strings.
LPCSTR szBuffer[2] = {"MyGlobalModule","OnGlobalCustomNotification"};
// Write the strings to the Event Viewer.
WriteEventViewerLog(szBuffer,2);
}
// Return processing to the pipeline.
return GL_NOTIFICATION_CONTINUE;
}
VOID Terminate()
{
// Remove the class from memory.
delete this;
}
private:
// Create a method that writes to the Event Viewer.
BOOL WriteEventViewerLog(LPCSTR szBuffer[], WORD wNumStrings)
{
// Test whether the handle for the Event Viewer is open.
if (NULL != m_hEventLog)
{
// Write any strings to the Event Viewer and return.
return ReportEvent(
m_hEventLog,
EVENTLOG_INFORMATION_TYPE,
0, 0, NULL, wNumStrings,
0, szBuffer, NULL );
}
return FALSE;
}
};
// Create the module's exported registration function.
HRESULT
__stdcall
RegisterModule(
DWORD dwServerVersion,
IHttpModuleRegistrationInfo * pModuleInfo,
IHttpServer * pGlobalInfo
)
{
UNREFERENCED_PARAMETER( dwServerVersion );
UNREFERENCED_PARAMETER( pGlobalInfo );
// Create an HRESULT to receive return values from methods.
HRESULT hr;
// Store the pointer for the global server interface.
g_pHttpServer = pGlobalInfo;
// Create an instance of the global module class.
MyGlobalModule * pGlobalModule = new MyGlobalModule;
// Test for an error.
if (NULL == pGlobalModule)
{
return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
}
// Set the global notifications.
hr = pModuleInfo->SetGlobalNotifications(
pGlobalModule, GL_PRE_BEGIN_REQUEST | GL_CUSTOM_NOTIFICATION );
// Test for an error and exit if necessary.
if (FAILED(hr))
{
return hr;
}
// Return a success status;
return S_OK;
}
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 Global-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 |
Consulte también
CGlobalModule (clase)
IHttpServer::NotifyCustomNotification (Método)