Metodo IHttpModuleRegistrationInfo::SetRequestNotifications
Registra le notifiche a livello di richiesta per un modulo.
Sintassi
virtual HRESULT SetRequestNotifications(
IN IHttpModuleFactory* pModuleFactory,
IN DWORD dwRequestNotifications,
IN DWORD dwPostRequestNotifications
) = 0;
Parametri
pModuleFactory
[IN] Puntatore a un'interfaccia IHttpModuleFactory .
dwRequestNotifications
[IN] Valore di maschera bit che contiene le notifiche di richiesta da registrare. (Definito in Httpserv.h.)
dwPostRequestNotifications
[IN] Valore di maschera bit contenente le notifiche post-evento da registrare. (Definito in Httpserv.h.)
Valore restituito
Oggetto HRESULT
. I valori possibili includono, ma non sono limitati a, quelli indicati nella tabella seguente.
Valore | Descrizione |
---|---|
S_OK | Indica che l'operazione ha avuto esito positivo. |
ERROR_ALREADY_EXISTS | Indica che il modulo è già stato registrato. |
Commenti
Il SetRequestNotifications
metodo registra le notifiche a livello di richiesta per una classe CHttpModule . Un modulo può registrare due eventi per ogni notifica: la notifica dell'evento, come indicato dalla maschera bit nel dwRequestNotifications
parametro e la notifica post-evento, come indicato dalla maschera di bit nel dwPostRequestNotifications
parametro.
Ad esempio, un modulo HTTP può registrarsi per la notifica RQ_AUTHENTICATE_REQUEST e la notifica post-evento per la stessa notifica. In questo modo, il modulo potrebbe fornire funzionalità di elaborazione aggiuntive per la notifica dell'evento e pulire eventuali dettagli di elaborazione nella notifica post-evento.
Nota
Alcuni eventi non hanno una notifica post-evento. Usare 0 per il dwPostRequestNotifications
parametro quando non si desidera notifica o quando la notifica post-evento non è supportata.
Nota
I valori di maschera bit per le notifiche a livello di richiesta sono definiti nel file Httpserv.h.
Il SetRequestNotifications
metodo richiede un puntatore a un'interfaccia IHttpModuleFactory , che IIS userà per creare un'istanza di una CHttpModule
classe. Questa factory deve gestire la creazione dell'istanza CHttpModule
della classe e la restituzione di eventuali messaggi di errore se la classe non può essere creata.
Esempio
Nell'esempio seguente viene illustrato come creare un modulo HTTP che usa la funzione RegisterModule e i metodi seguenti per registrare un modulo per le notifiche a livello globale e a livello di richiesta.
Il
SetRequestNotifications
metodo registra una classe per unaCHttpModule
notifica OnBeginRequest a livello di richiesta.Il metodo SetPriorityForRequestNotification imposta la priorità del modulo per le notifiche a livello di richiesta.
Il metodo SetGlobalNotifications registra una classe CGlobalModule per una notifica OnGlobalPreBeginRequest a livello globale.
Il metodo SetPriorityForGlobalNotification imposta la priorità del modulo per la notifica a livello globale.
Il modulo risponde alle notifiche registrate e scrive le voci nel log dell'applicazione nel Visualizzatore eventi.
Nota
Le voci nella Visualizzatore eventi visualizzeranno "IISADMIN" come origine evento.
#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <httpserv.h>
// Create a global handle for the Event Viewer.
HANDLE g_hEventLog;
// Define the method that writes to the Event Viewer.
BOOL WriteEventViewerLog(LPCSTR szBuffer[], WORD wNumStrings);
// Create the HTTP module class.
class MyHttpModule : public CHttpModule
{
public:
REQUEST_NOTIFICATION_STATUS
OnBeginRequest(
IN IHttpContext * pHttpContext,
IN IHttpEventProvider * pProvider
)
{
UNREFERENCED_PARAMETER( pHttpContext );
UNREFERENCED_PARAMETER( pProvider );
// Create an array of strings.
LPCSTR szBuffer[2] = {"MyHttpModule","OnBeginRequest"};
// Write the strings to the Event Viewer.
WriteEventViewerLog(szBuffer,2);
// Return processing to the pipeline.
return RQ_NOTIFICATION_CONTINUE;
}
};
// Create the module's global class.
class MyGlobalModule : public CGlobalModule
{
public:
GLOBAL_NOTIFICATION_STATUS
OnGlobalPreBeginRequest(
IN IPreBeginRequestProvider * pProvider
)
{
UNREFERENCED_PARAMETER( pProvider );
// Create an array of strings.
LPCSTR szBuffer[2] = {"MyGlobalModule","OnGlobalPreBeginRequest"};
// 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;
}
MyGlobalModule()
{
// Open a handle to the Event Viewer.
g_hEventLog = RegisterEventSource( NULL,"IISADMIN" );
}
~MyGlobalModule()
{
// Test whether the handle for the Event Viewer is open.
if (NULL != g_hEventLog)
{
DeregisterEventSource( g_hEventLog );
g_hEventLog = NULL;
}
}
};
// Create the module's class factory.
class MyHttpModuleFactory : public IHttpModuleFactory
{
public:
HRESULT
GetHttpModule(
OUT CHttpModule ** ppModule,
IN IModuleAllocator * pAllocator
)
{
UNREFERENCED_PARAMETER( pAllocator );
// Create a new instance.
MyHttpModule * pModule = new MyHttpModule;
// Test for an error.
if (!pModule)
{
// Return an error if the factory cannot create the instance.
return HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY );
}
else
{
// Return a pointer to the module.
*ppModule = pModule;
pModule = NULL;
// Return a success status.
return S_OK;
}
}
void Terminate()
{
// Remove the class from memory.
delete this;
}
};
// Define 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 != g_hEventLog)
{
// Write any strings to the Event Viewer and return.
return ReportEvent(
g_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;
// Set the request notifications.
hr = pModuleInfo->SetRequestNotifications(
new MyHttpModuleFactory,
RQ_BEGIN_REQUEST, 0 );
// Test for an error and exit if necessary.
if (FAILED(hr))
{
return hr;
}
// Set the request priority.
hr = pModuleInfo->SetPriorityForRequestNotification(
RQ_BEGIN_REQUEST,PRIORITY_ALIAS_MEDIUM);
// Test for an error and exit if necessary.
if (FAILED(hr))
{
return hr;
}
// 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 );
// Test for an error and exit if necessary.
if (FAILED(hr))
{
return hr;
}
// Set the global priority.
hr = pModuleInfo->SetPriorityForGlobalNotification(
GL_PRE_BEGIN_REQUEST,PRIORITY_ALIAS_LOW);
// Test for an error and exit if necessary.
if (FAILED(hr))
{
return hr;
}
// Return a success status;
return S_OK;
}
Il modulo deve esportare la RegisterModule
funzione. È possibile esportare questa funzione creando un file di definizione del modulo (con estensione def) per il progetto oppure è possibile compilare il modulo usando l'opzione /EXPORT:RegisterModule
. Per altre informazioni, vedere Procedura dettagliata: Creazione di un modulo HTTP Request-Level tramite codice nativo.
Facoltativamente, è possibile compilare il codice usando la __stdcall (/Gz)
convenzione chiamante anziché dichiarare esplicitamente la convenzione chiamante per ogni funzione.
Requisiti
Tipo | Descrizione |
---|---|
Client | - IIS 7.0 in Windows Vista - IIS 7.5 in Windows 7 - IIS 8.0 in Windows 8 - IIS 10.0 in Windows 10 |
Server | - IIS 7.0 in Windows Server 2008 - IIS 7.5 in Windows Server 2008 R2 - IIS 8.0 in Windows Server 2012 - IIS 8.5 in Windows Server 2012 R2 - IIS 10.0 in Windows Server 2016 |
Prodotto | - 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 |
Intestazione | Httpserv.h |
Vedere anche
Interfaccia IHttpModuleRegistrationInfo
Metodo IHttpModuleRegistrationInfo::SetGlobalNotifications
Metodo IHttpModuleRegistrationInfo::SetPriorityForGlobalNotification
Metodo IHttpModuleRegistrationInfo::SetPriorityForRequestNotification
funzione PFN_REGISTERMODULE