Bagikan melalui


IHttpContext::GetNextNotification Method

Mengambil pemberitahuan berikutnya untuk host modul saat ini.

Sintaks

virtual BOOL GetNextNotification(  
   IN REQUEST_NOTIFICATION_STATUS status,  
   OUT DWORD* pdwNotification,  
   OUT BOOL* pfIsPostNotification,  
   OUT CHttpModule** ppModuleInfo,  
   OUT IHttpEventProvider** ppRequestOutput  
) = 0;  

Parameter

status
[IN] Nilai enumerasi REQUEST_NOTIFICATION_STATUS untuk dikembalikan dari pemberitahuan saat ini.

pdwNotification
[OUT] Penunjuk ke yang DWORD berisi nilai bitmask untuk pemberitahuan berikutnya.

pfIsPostNotification
[OUT] Penunjuk ke nilai Boolean. true untuk menunjukkan bahwa pemberitahuan adalah pasca-pemberitahuan; jika tidak, false.

ppModuleInfo
[OUT] Penunjuk ke alamat kelas CHttpModule yang bertanggung jawab untuk memproses pemberitahuan yang dikembalikan.

ppRequestOutput
[OUT] Penunjuk ke alamat antarmuka IHttpEventProvider untuk pemberitahuan yang dikembalikan.

Tampilkan Nilai

true jika panggilan ke GetNextNotification berhasil; jika tidak, false.

Keterangan

Modul HTTP dapat menggunakan GetNextNotification metode untuk menggabungkan pemberitahuan dalam host modul yang sama. Mengembalikan pemrosesan ke alur pemrosesan permintaan terintegrasi memerlukan sejumlah kecil overhead. Untuk melewati overhead tersebut, modul HTTP dapat memanggil GetNextNotification metode untuk melompat ke pemberitahuan berikutnya dan melanjutkan pemrosesan, asalkan kedua pemberitahuan berada dalam host modul yang sama dan tidak ada penangan pemberitahuan tambahan yang terdaftar untuk memproses permintaan antar pemberitahuan.

Misalnya, modul HTTP mungkin berisi metode OnResolveRequestCache , dan modul HTTP lain dalam host modul yang sama mungkin berisi metode OnPostResolveRequestCache . Modul pertama dapat memanggil GetNextNotification metode untuk melanjutkan pemrosesan, daripada mengembalikan pemrosesan ke alur, seolah-olah modul telah mendaftar untuk OnPostResolveRequestCache metode pemberitahuan pasca-peristiwa.

Catatan

Jika panggilan untuk GetNextNotification mengembalikan false, Anda dapat mengaktifkan aturan failed-request-tracing yang akan memungkinkan Anda memeriksa pemberitahuan mana yang sedang diproses IIS.

Contoh

Contoh kode berikut menunjukkan cara membuat modul HTTP yang melakukan tugas berikut:

  1. Mendaftar untuk beberapa pemberitahuan.

  2. Membuat metode pembantu yang memanggil GetNextNotification metode , yang mencoba melompat ke pemberitahuan berikutnya.

  3. Untuk setiap pemberitahuan terdaftar, menentukan penangan pemberitahuan yang memanggil metode pembantu, lalu menampilkan status pengembalian ke klien.

#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
    )
    {
        UNREFERENCED_PARAMETER( pProvider );

        // 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 processing to the pipeline.
        return RQ_NOTIFICATION_CONTINUE;
    }

    REQUEST_NOTIFICATION_STATUS
    OnAuthenticateRequest(
        IN IHttpContext * pHttpContext,
        IN IAuthenticationProvider * pProvider
    )
    {
        UNREFERENCED_PARAMETER( pProvider );
        // Attempt to retrieve the next notification and display the result.
        GetNotificationAndDisplayResult(
            pHttpContext,"OnAuthenticateRequest\n");
        // Return processing to the pipeline.
        return RQ_NOTIFICATION_CONTINUE;
    }

    REQUEST_NOTIFICATION_STATUS
    OnPostAuthenticateRequest(
        IN IHttpContext * pHttpContext,
        IN IHttpEventProvider * pProvider
    )
    {
        UNREFERENCED_PARAMETER( pProvider );
        // Attempt to retrieve the next notification and display the result.
        GetNotificationAndDisplayResult(
            pHttpContext,"\nOnPostAuthenticateRequest\n");
        // Return processing to the pipeline.
        return RQ_NOTIFICATION_CONTINUE;
    }

    REQUEST_NOTIFICATION_STATUS
    OnAuthorizeRequest(
        IN IHttpContext * pHttpContext,
        IN IHttpEventProvider * pProvider
    )
    {
        UNREFERENCED_PARAMETER( pProvider );
        // Attempt to retrieve the next notification and display the result.
        GetNotificationAndDisplayResult(
            pHttpContext,"\nOnAuthorizeRequest\n");
        // Return processing to the pipeline.
        return RQ_NOTIFICATION_CONTINUE;
    }

    REQUEST_NOTIFICATION_STATUS
    OnPostAuthorizeRequest(
        IN IHttpContext * pHttpContext,
        IN IHttpEventProvider * pProvider
    )
    {
        UNREFERENCED_PARAMETER( pProvider );
        // Attempt to retrieve the next notification and display the result.
        GetNotificationAndDisplayResult(
            pHttpContext,"\nOnPostAuthorizeRequest\n");
        // Return processing to the pipeline.
        return RQ_NOTIFICATION_CONTINUE;
    }

    REQUEST_NOTIFICATION_STATUS
    OnMapRequestHandler(
        IN IHttpContext * pHttpContext,
        IN IMapHandlerProvider * pProvider
    )
    {
        UNREFERENCED_PARAMETER( pHttpContext );
        UNREFERENCED_PARAMETER( pProvider );
        // End additional processing.        
        return RQ_NOTIFICATION_FINISH_REQUEST;
    }

private:

    // Create a helper method that attempts to retrieve the next
    // notification and returns the status to a Web client.
    void GetNotificationAndDisplayResult(
        IHttpContext * pHttpContext,
        PCSTR pszBuffer
    )
    {
        DWORD dwNotification = 0;
        BOOL fPostNotification = FALSE;
        CHttpModule * pHttpModule = NULL;
        IHttpEventProvider * pEventProvider = NULL;
        char szBuffer[256]="";

        // Attempt to retrive the next notification.
        BOOL fReturn = pHttpContext->GetNextNotification(
            RQ_NOTIFICATION_CONTINUE,
            &dwNotification,&fPostNotification,
            &pHttpModule,&pEventProvider);

        // Return the name of the notification to a Web client.
        WriteResponseMessage(pHttpContext,pszBuffer);

        // Return the status of the GetNextNotification method to a Web client.
        sprintf_s(szBuffer,255,"\tGetNextNotification return value: %s\n",
            fReturn==TRUE?"true":"false");
        WriteResponseMessage(pHttpContext,szBuffer);

        // Return the notification bitmask to a Web client.
        sprintf_s(szBuffer,255,"\tNotification: %08x\n",dwNotification);
        WriteResponseMessage(pHttpContext,szBuffer);

        // Return whether the notification is a post-notification.
        sprintf_s(szBuffer,255,"\tPost-notification: %s\n",
            fPostNotification==TRUE?"Yes":"No");
        WriteResponseMessage(pHttpContext,szBuffer);
    }

    // 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. (Defined in the Http.h file.)
        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 we 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 );

    return pModuleInfo->SetRequestNotifications(
        new MyHttpModuleFactory,
        RQ_BEGIN_REQUEST | RQ_AUTHENTICATE_REQUEST | 
        RQ_AUTHORIZE_REQUEST | RQ_MAP_REQUEST_HANDLER,
        RQ_AUTHENTICATE_REQUEST | RQ_AUTHORIZE_REQUEST
    );
}

Modul Anda harus mengekspor fungsi RegisterModule . Anda dapat mengekspor fungsi ini dengan membuat file definisi modul (.def) untuk proyek Anda, atau Anda dapat mengkompilasi modul dengan menggunakan sakelar /EXPORT:RegisterModule . Untuk informasi selengkapnya, lihat Panduan: Membuat Modul HTTP Request-Level Dengan Menggunakan Kode Asli.

Anda dapat secara opsional mengkompilasi kode dengan menggunakan __stdcall (/Gz) konvensi panggilan alih-alih secara eksplisit mendeklarasikan konvensi panggilan untuk setiap fungsi.

Persyaratan

Jenis Deskripsi
Klien - IIS 7.0 di Windows Vista
- IIS 7.5 di Windows 7
- IIS 8.0 di Windows 8
- IIS 10.0 pada Windows 10
Server - IIS 7.0 di Windows Server 2008
- IIS 7.5 di Windows Server 2008 R2
- IIS 8.0 di Windows Server 2012
- IIS 8.5 di Windows Server 2012 R2
- IIS 10.0 di Windows Server 2016
Produk - 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

Lihat juga

Antarmuka IHttpContext