IHttpContext::GetNextNotification 메서드
현재 모듈 호스트에 대한 다음 알림을 검색합니다.
구문
virtual BOOL GetNextNotification(
IN REQUEST_NOTIFICATION_STATUS status,
OUT DWORD* pdwNotification,
OUT BOOL* pfIsPostNotification,
OUT CHttpModule** ppModuleInfo,
OUT IHttpEventProvider** ppRequestOutput
) = 0;
매개 변수
status
[IN] 현재 알림에서 반환할 REQUEST_NOTIFICATION_STATUS 열거형 값입니다.
pdwNotification
[OUT] 다음 알림에 DWORD
대한 비트 마스크 값을 포함하는 에 대한 포인터입니다.
pfIsPostNotification
[OUT] 부울 값에 대한 포인터입니다. true
알림이 사후 알림임을 나타내려면 그렇지 않으면 입니다 false
.
ppModuleInfo
[OUT] 반환된 알림 처리를 담당하는 CHttpModule 클래스의 주소에 대한 포인터입니다.
ppRequestOutput
[OUT] 반환된 알림에 대한 IHttpEventProvider 인터페이스의 주소에 대한 포인터입니다.
반환 값
true
에 대한 GetNextNotification
호출이 성공하면 이고, false
그렇지 않으면 입니다.
설명
HTTP 모듈은 메서드를 GetNextNotification
사용하여 동일한 모듈 호스트 내에서 알림을 병합할 수 있습니다. 통합 요청 처리 파이프라인으로 처리를 반환하려면 약간의 오버헤드가 필요합니다. 이러한 오버헤드를 우회하기 위해 HTTP 모듈은 메서드를 호출 GetNextNotification
하여 다음 알림으로 건너뛰고 처리를 계속할 수 있습니다. 두 알림이 동일한 모듈 호스트 내에 있고 알림 간에 요청을 처리하기 위해 추가 알림 처리기가 등록되지 않은 경우.
예를 들어 HTTP 모듈에는 OnResolveRequestCache 메서드가 포함될 수 있으며 동일한 모듈 호스트 내의 다른 HTTP 모듈에는 OnPostResolveRequestCache 메서드가 포함될 수 있습니다. 첫 번째 모듈은 모듈이 GetNextNotification
이벤트 후 알림 메서드에 이미 등록된 OnPostResolveRequestCache
것처럼 파이프라인에 처리를 반환하는 대신 메서드를 호출하여 처리를 계속할 수 있습니다.
참고
에 대한 호출이 를 반환false
하는 GetNextNotification
경우 IIS가 처리 중인 알림을 검사할 수 있는 실패한 요청 추적 규칙을 사용하도록 설정할 수 있습니다.
예제
다음 코드 예제에서는 다음 작업을 수행하는 HTTP 모듈을 만드는 방법을 보여 줍니다.
여러 알림을 등록합니다.
다음 알림으로 건너뛰려고 시도하는 메서드를 호출
GetNextNotification
하는 도우미 메서드를 만듭니다.등록된 각 알림에 대해 도우미 메서드를 호출하는 알림 처리기를 정의한 다음 클라이언트에 대한 반환 상태 표시합니다.
#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
);
}
모듈은 RegisterModule 함수를 내보내야 합니다. 프로젝트에 대한 모듈 정의(.def) 파일을 만들어 이 함수를 내보내거나 스위치를 사용하여 모듈을 /EXPORT:RegisterModule
컴파일할 수 있습니다. 자세한 내용은 연습: 네이티브 코드를 사용하여 Request-Level HTTP 모듈 만들기를 참조하세요.
필요에 따라 각 함수에 대한 호출 규칙을 명시적으로 선언하는 대신 호출 규칙을 사용하여 __stdcall (/Gz)
코드를 컴파일할 수 있습니다.
요구 사항
형식 | Description |
---|---|
클라이언트 | - 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 |
헤더 | Httpserv.h |