IHttpModuleRegistrationInfo::SetPriorityForGlobalNotification メソッド
モジュールのグローバル レベルの優先度を設定します。
構文
virtual HRESULT SetPriorityForGlobalNotification(
IN DWORD dwGlobalNotification,
IN PCWSTR pszPriority
) = 0;
パラメーター
dwGlobalNotification
[IN]優先度レベルに設定するグローバル通知を含むビットマスク値。 ( Httpserv.h で定義されています。)
pszPriority
[IN]優先度エイリアスを含む文字列へのポインター。 (Httpserv.h で定義されています。)
戻り値
HRESULT
。 有効な値を次の表に示しますが、これ以外にもあります。
値 | 説明 |
---|---|
S_OK | 操作が成功したことを示します。 |
解説
メソッドは SetPriorityForGlobalNotification
、HTTP モジュールが登録されているグローバル レベルの通知の一覧の優先度レベルを設定します。 IIS では、優先度レベルを使用して、モジュールを整理する必要があることを通知内で順序を決定します。 たとえば、エイリアスを使用して OnGlobalPreBeginRequest 通知に登録したグローバル モジュールは、エイリアスを使用 PRIORITY_ALIAS_HIGH
して OnGlobalPreBeginRequest 通知 PRIORITY_ALIAS_LOW
に登録されたモジュールの前に優先されます。
注意
グローバル レベルの通知と優先度エイリアスのビットマスク値は、Httpserv.h ファイルで定義されます。
例
次のコード例では、 RegisterModule 関数と次のメソッドを使用してグローバル レベルおよび要求レベルの通知用のモジュールを登録する HTTP モジュールを作成する方法を示します。
SetRequestNotifications メソッドは、要求レベルの OnBeginRequest 通知用に CHttpModule クラスを登録します。
SetPriorityForRequestNotification メソッドは、要求レベルの通知に対するモジュールの優先度を設定します。
SetGlobalNotifications メソッドは、グローバル レベルの OnGlobalPreBeginRequest 通知用に CGlobalModule クラスを登録します。
メソッドは
SetPriorityForGlobalNotification
、グローバル レベルの通知に対するモジュールの優先度を設定します。モジュールは、登録された通知に応答し、イベント ビューアーのアプリケーション ログにエントリを書き込みます。
注意
イベント ビューアーのエントリには、イベント ソースとして "IISADMIN" が表示されます。
#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;
}
モジュールで 関数をエクスポートする RegisterModule
必要があります。 この関数をエクスポートするには、プロジェクトのモジュール定義 (.def) ファイルを作成するか、スイッチを使用してモジュールを /EXPORT:RegisterModule
コンパイルします。 詳細については、「 チュートリアル: ネイティブ コードを使用したRequest-Level HTTP モジュールの作成」を参照してください。
必要に応じて、各関数の呼び出し規約を __stdcall (/Gz)
明示的に宣言するのではなく、呼び出し規約を使用してコードをコンパイルできます。
要件
Type | 説明 |
---|---|
Client | - 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 |
Header | Httpserv.h |
参照
IHttpModuleRegistrationInfo インターフェイス
IHttpModuleRegistrationInfo::SetGlobalNotifications メソッド
IHttpModuleRegistrationInfo::SetPriorityForRequestNotification メソッド
IHttpModuleRegistrationInfo::SetRequestNotifications メソッド
PFN_REGISTERMODULE関数