IHttpEventProvider インターフェイス

汎用イベント レポート インターフェイスを提供します。

構文

class IHttpEventProvider  

メソッド

次の表に、 クラスによって公開されるメソッドの一覧を IHttpEventProvider 示します。

名前 説明
SetErrorStatus 返すエラーを指定します。

派生クラス

次の表は、 インターフェイスによって公開される派生クラスの一覧です IHttpEventProvider

名前 説明
IAuthenticationProvider イベント通知を RQ_REQUEST_AUTHENTICATE するためのインターフェイスを提供します。
ICacheProvider イベント通知を GL_CACHE_OPERATION するためのインターフェイスを提供します。
ICustomNotificationProvider イベント通知を GL_CUSTOM_NOTIFCATION および RQ_CUSTOM_NOTIFCATION するためのインターフェイスを提供します。
IGlobalConfigurationChangeProvider イベント通知を GL_CONFIGURATION_CHANGE するためのインターフェイスを提供します。
IGlobalFileChangeProvider イベント通知を GL_FILE_CHANGE するためのインターフェイスを提供します。
IGlobalRSCAQueryProvider イベント通知を GL_RSCA_QUERY するためのインターフェイスを提供します。
IGlobalStopListeningProvider イベント通知を GL_STOP_LISTENING するためのインターフェイスを提供します。
IGlobalThreadCleanupProvider イベント通知を GL_THREAD_CLEANUP するためのインターフェイスを提供します。
IGlobalTraceEventProvider イベント通知を GL_TRACE_EVENT するためのインターフェイスを提供します。
IHttpApplicationProvider イベント通知を GL_APPLICATION_START するためのインターフェイスを提供します。
IMapHandlerProvider イベント通知を RQ_DETERMINE_HANDLER するためのインターフェイスを提供します。
IMapPathProvider イベント通知を RQ_MAP_PATH するためのインターフェイスを提供します。
IPreBeginRequestProvider イベント通知を GL_PRE_BEGIN_REQUEST するためのインターフェイスを提供します。
IReadEntityProvider イベント通知を RQ_READ_ENTITY するためのインターフェイスを提供します。
ISendResponseProvider イベント通知を RQ_SEND_RESPONSE するためのインターフェイスを提供します。

解説

インターフェイスは IHttpEventProvider 、ほとんどの通知メソッドに汎用イベント レポート インターフェイスを提供し、残りの通知で使用されるイベント レポート インターフェイスの親クラスとして機能します。

インターフェイスは IHttpEventProvider 、現在のコンテキストのエラー状態を設定する SetErrorStatus メソッドのみを公開します。 から IHttpEventProvider 継承される派生クラスのいくつかは、それぞれのイベントに固有の追加のメソッドを公開します。

次のコード例では、Web クライアントに文字列の例を送信し、この操作から戻り値をキャプチャする HTTP モジュールを作成する方法を示します。 モジュールでは、 メソッドを SetErrorStatus 使用して、現在の要求のエラー状態として戻り値を指定し、終了します。

#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <httpserv.h>

// Create the module class.
class MyHttpModule : public CHttpModule
{
public:
    REQUEST_NOTIFICATION_STATUS
    OnBeginRequest(
        IN IHttpContext * pHttpContext,
        IN IHttpEventProvider * pProvider
    )
    {
        // Create an HRESULT to receive return values from methods.
        HRESULT hr;

        // Clear the existing response.
        pHttpContext->GetResponse()->Clear();
        // Set the MIME type to plain text.
        pHttpContext->GetResponse()->SetHeader(
            HttpHeaderContentType,"text/plain",
            (USHORT)strlen("text/plain"),TRUE);

        // Return a simple message to the Web client.
        hr = WriteResponseMessage(pHttpContext,"Hello World!");

        // Set the error status for the module.
        pProvider->SetErrorStatus( hr );

        // End additional processing.
        return RQ_NOTIFICATION_FINISH_REQUEST;
    }

private:

    // Create a utility method that inserts a string value into the response.
    HRESULT WriteResponseMessage(
        IHttpContext * pHttpContext,
        PCSTR pszBuffer
    )
    {
        // Create an HRESULT to receive return values from methods.
        HRESULT hr;
        
        // Create a data chunk.
        HTTP_DATA_CHUNK dataChunk;
        // Set the chunk to a chunk in memory.
        dataChunk.DataChunkType = HttpDataChunkFromMemory;
        // Buffer for bytes written of data chunk.
        DWORD cbSent;

        // Set the chunk to the buffer.
        dataChunk.FromMemory.pBuffer =
            (PVOID) pszBuffer;
        // Set the chunk size to the buffer size.
        dataChunk.FromMemory.BufferLength =
            (USHORT) strlen(pszBuffer);
        // Insert the data chunk into the response.
        hr = pHttpContext->GetResponse()->WriteEntityChunks(
            &dataChunk,1,FALSE,TRUE,&cbSent);
        // Test for an error.
        if (FAILED(hr))
        {
            // Return the error status.
            return hr;
        }

        // Return a success status.
        return S_OK;
    }
};

// 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;
    }
};

// Create the module's exported registration function.
HRESULT
__stdcall
RegisterModule(
    DWORD dwServerVersion,
    IHttpModuleRegistrationInfo * pModuleInfo,
    IHttpServer * pGlobalInfo
)
{
    UNREFERENCED_PARAMETER( dwServerVersion );
    UNREFERENCED_PARAMETER( pGlobalInfo );

    // Set the request notifications and exit.
    return pModuleInfo->SetRequestNotifications(
        new MyHttpModuleFactory,
        RQ_BEGIN_REQUEST,
        0
    );
}

モジュールで 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

参照

Web Server Core インターフェイス
IAuthenticationProvider インターフェイス
ICacheProvider インターフェイス
ICustomNotificationProvider インターフェイス
IGlobalConfigurationChangeProvider インターフェイス
IGlobalFileChangeProvider インターフェイス
IGlobalRSCAQueryProvider インターフェイス
IGlobalStopListeningProvider インターフェイス
IGlobalThreadCleanupProvider インターフェイス
IGlobalTraceEventProvider インターフェイス
IHttpApplicationProvider インターフェイス
IMapHandlerProvider インターフェイス
IMapPathProvider インターフェイス
IPreBeginRequestProvider インターフェイス
IReadEntityProvider インターフェイス
ISendResponseProvider インターフェイス