Método IHttpContext::GetIsLastNotification
Indica se há mais notificações pendentes para essa solicitação no host do módulo atual.
Sintaxe
virtual BOOL GetIsLastNotification(
IN REQUEST_NOTIFICATION_STATUS status
) = 0;
Parâmetros
status
[IN] Um valor de enumeração REQUEST_NOTIFICATION_STATUS .
Valor Retornado
true
se notificações adicionais estiverem pendentes; caso contrário, false
.
Comentários
O GetIsLastNotification
método recupera o status de notificações pendentes para a solicitação atual no host do módulo atual. Ou seja, o GetIsLastNotification
método não indica se notificações adicionais estão pendentes para outra solicitação ou se notificações adicionais estão pendentes para um módulo que está sendo executado em um host de módulo diferente.
O valor do status
parâmetro afeta diretamente o valor retornado para o GetIsLastNotification
método . Por exemplo, especificar RQ_NOTIFICATION_CONTINUE pode retornar true
para indicar que notificações adicionais estão pendentes, enquanto especificar RQ_NOTIFICATION_FINISH_REQUEST pode retornar false
para a mesma solicitação. Esse comportamento ocorre porque um valor status de RQ_NOTIFICATION_CONTINUE
continuará a processar notificações adicionais das quais um valor status seria RQ_NOTIFICATION_FINISH_REQUEST
ignorado.
Exemplo
O exemplo de código a seguir demonstra como usar o GetIsLastNotification
método para criar um módulo HTTP que indica se mais notificações estão pendentes para a solicitação atual. Em seguida, o módulo retorna essas informações para o cliente Web.
#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 );
// Retrieve if this is the last notification.
BOOL bIsLastNotification;
bIsLastNotification = pHttpContext->GetIsLastNotification(
RQ_NOTIFICATION_FINISH_REQUEST);
// 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 string to the client whether this is the last notification.
WriteResponseMessage(pHttpContext,"Last Notification: ",
(TRUE==bIsLastNotification)?"Yes":"No");
// End additional processing.
return RQ_NOTIFICATION_FINISH_REQUEST;
}
private:
// Create a utility method that inserts a name/value pair into the response.
HRESULT WriteResponseMessage(
IHttpContext * pHttpContext,
PCSTR pszName,
PCSTR pszValue
)
{
// 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 first buffer.
dataChunk.FromMemory.pBuffer =
(PVOID) pszName;
// Set the chunk size to the first buffer size.
dataChunk.FromMemory.BufferLength =
(USHORT) strlen(pszName);
// 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;
}
// Set the chunk to the second buffer.
dataChunk.FromMemory.pBuffer =
(PVOID) pszValue;
// Set the chunk size to the second buffer size.
dataChunk.FromMemory.BufferLength =
(USHORT) strlen(pszValue);
// 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,
0
);
}
Seu módulo deve exportar a função RegisterModule . Você pode exportar essa função criando um arquivo de definição de módulo (.def) para seu projeto ou pode compilar o módulo usando a opção /EXPORT:RegisterModule
. Para obter mais informações, consulte Passo a passo: criando um módulo HTTP Request-Level usando código nativo.
Você pode compilar o código usando a __stdcall (/Gz)
convenção de chamada em vez de declarar explicitamente a convenção de chamada para cada função.
Requisitos
Tipo | Descrição |
---|---|
Cliente | - IIS 7.0 no Windows Vista - IIS 7.5 no Windows 7 - IIS 8.0 no Windows 8 - IIS 10.0 no Windows 10 |
Servidor | - IIS 7.0 no Windows Server 2008 - IIS 7.5 no Windows Server 2008 R2 - IIS 8.0 no Windows Server 2012 - IIS 8.5 no Windows Server 2012 R2 - IIS 10.0 no Windows Server 2016 |
Produto | - 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 |
parâmetro | Httpserv.h |
Consulte Também
IHttpContext Interface
Método IHttpContext::D isableNotifications
Método IHttpContext::GetNextNotification