Metodo IHttpModuleRegistrationInfo::SetPriorityForRequestNotification
Imposta la priorità a livello di richiesta per un modulo.
Sintassi
virtual HRESULT SetPriorityForRequestNotification(
IN DWORD dwRequestNotification,
IN PCWSTR pszPriority
) = 0;
Parametri
dwRequestNotification
[IN] Valore della maschera di bit che contiene le notifiche di richiesta da impostare per il livello di priorità. (Definito in Httpserv.h.)
pszPriority
[IN] Puntatore a una stringa contenente l'alias di priorità. (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 è riuscita. |
Commenti
Il SetPriorityForRequestNotification
metodo imposta il livello di priorità per un elenco di notifiche a livello di richiesta per cui è stato registrato un modulo HTTP. IIS usa il livello di priorità per determinare l'ordine all'interno di una notifica che i moduli devono essere organizzati. I livelli di priorità vengono invertiti per le notifiche CHttpModule::OnSendResponse . Ad esempio, un modulo HTTP registrato per la notifica CHttpModule::OnBeginRequest usando l'alias verrebbe assegnato in PRIORITY_ALIAS_HIGH
ordine di priorità prima di un modulo registrato per la OnBeginRequest
notifica usando l'alias PRIORITY_ALIAS_LOW
. Un modulo HTTP registrato per la OnSendResponse
notifica usando l'alias PRIORITY_ALIAS_HIGH
viene eseguito dopo un modulo registrato per la OnSendResponse
notifica usando l'alias PRIORITY_ALIAS_LOW
.
Nota
I valori della maschera di bit per le notifiche a livello di richiesta e gli alias di priorità sono definiti nel file Httpserv.h.
Nota
I livelli di priorità vengono invertiti per RQ_SEND_RESPONSE
le notifiche.
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 metodo SetRequestNotifications registra una classe CHttpModule per una notifica OnBeginRequestRequest a livello di richiesta.
Il
SetPriorityForRequestNotification
metodo 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 applicazioni nel Visualizzatore eventi.
Nota
Le voci nel 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 di chiamata anziché dichiarare in modo esplicito la convenzione di chiamata 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::SetRequestNotifications
Funzione PFN_REGISTERMODULE