Método IHttpTraceContext::QuickTrace
Grava uma mensagem no log de rastreamento do IIS.
Sintaxe
virtual
HRESULT
QuickTrace(
IN PCWSTR pszData1,
IN PCWSTR pszData2 = NULL,
IN HRESULT hrLastError = S_OK,
IN UCHAR Level = 4
) = 0;
Parâmetros
Parâmetro | Descrição |
---|---|
pszData1 |
Uma mensagem para registrar. |
pszData2 |
Uma segunda mensagem a ser registrada. |
hrLastError |
O HRESULT a ser registrado. O padrão é S_OK. |
level |
O nível de rastreamento. Os valores possíveis são de 1 a 7. O padrão é 4 (TRACE_LEVEL_INFORMATION). Para obter mais informações, consulte a seção Comentários. |
Valor Retornado
Um HRESULT
. Os possíveis valores incluem, mas sem limitação, aqueles na tabela a seguir.
Valor | Descrição |
---|---|
S_OK | Indica que a operação foi bem-sucedida. |
Comentários
Os níveis de rastreamento de eventos de 1 a 5 correspondem aos níveis de rastreamento do ETW (Rastreamento de Eventos para Windows). Para obter mais informações sobre esses níveis de rastreamento, consulte a estrutura EVENT_TRACE_HEADER . Você também pode usar o nível de rastreamento 6 (definido como HTTP_TRACE_LEVEL_START no arquivo de cabeçalho Httptrace.h) e o nível de rastreamento 7 (definido como HTTP_TRACE_LEVEL_END em Httptrace.h).
Exemplo
O exemplo a seguir demonstra como usar o método IHttpRequest::SetUrl para alterar uma URL solicitada para outra URL e registrar a alteração com o QuickTrace
método .
Você deve habilitar o rastreamento de Solicitação de Evento Com Falha para ver o evento.
HRESULT GLOBAL_MODULE::Initialize( VOID ){
return S_OK;
}
// CGlobalModule derived classes must implement Terminate
// And free memory
//
VOID GLOBAL_MODULE::Terminate( VOID){
delete this;
}
GLOBAL_NOTIFICATION_STATUS
GLOBAL_MODULE::OnGlobalPreBeginRequest(
IPreBeginRequestProvider* pProvider
)
{
HRESULT hr = S_OK;
IHttpContext* pContext = pProvider->GetHttpContext( );
IHttpRequest* pRequest = pContext->GetRequest( );
IHttpResponse* pResponse = pContext->GetResponse( );
PCWSTR rqUrl = pContext->GetRequest()->GetRawHttpRequest()->CookedUrl.pAbsPath;
OutputDebugStringW(rqUrl);
//
// Change only specific URL requests.
//
wchar_t URLask[] = L"/rPost.htm";
wchar_t URLreset[] = L"/Test.htm";
if(!wcscmp(rqUrl,URLask)){
hr = pRequest->SetUrl( URLreset, sizeof( URLreset )/sizeof(URLreset[0]) - 1, TRUE );
pContext->GetTraceContext( )->QuickTrace( L"URL change from rPost to", URLreset );
}
if( FAILED( hr ) )
goto Finished;
Finished:
if( FAILED( hr ) ){
pResponse->SetStatus( 500, "Internal Server Error", 0, hr );
return GL_NOTIFICATION_HANDLED;
}
return GL_NOTIFICATION_CONTINUE;
}
/*
#include "stdafx.h"
HRESULT GLOBAL_MODULE::Initialize( VOID ){
return S_OK;
}
// CGlobalModule derrived classes must implement Terminate
// And free memory
//
VOID GLOBAL_MODULE::Terminate( VOID){
delete this;
}
GLOBAL_NOTIFICATION_STATUS
GLOBAL_MODULE::OnGlobalPreBeginRequest(
IPreBeginRequestProvider* pProvider
)
{
HRESULT hr = S_OK;
IHttpContext* pContext = pProvider->GetHttpContext( );
IHttpRequest* pRequest = pContext->GetRequest( );
IHttpResponse* pResponse = pContext->GetResponse( );
PCWSTR rqUrl = pContext->GetRequest()->GetRawHttpRequest()->CookedUrl.pAbsPath;
OutputDebugStringW(rqUrl);
//
// Change only specific URL requests.
//
wchar_t URLask[] = L"/rPost.htm";
wchar_t URLreset[] = L"/Test.htm";
if(!wcscmp(rqUrl,URLask)){
hr = pRequest->SetUrl( URLreset, sizeof( URLreset )/sizeof(URLreset[0]) - 1, TRUE );
pContext->GetTraceContext( )->QuickTrace( L"URL change to test " );
}
if( FAILED( hr ) )
goto Finished;
Finished:
if( FAILED( hr ) ){
pResponse->SetStatus( 500, "Internal Server Error", 0, hr );
// returning GL_NOTIFICATION_HANDLED means end the request
return GL_NOTIFICATION_HANDLED;
}
return GL_NOTIFICATION_CONTINUE;
}
*/
int _tmain(int argc, _TCHAR* argv[])
{
printf("It works!");
return 0;
}
#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 a pointer to the request.
IHttpRequest * pHttpRequest = pHttpContext->GetRequest();
// Test for an error.
if (pHttpRequest != NULL)
{
// Specify an OPTIONS request method.
HRESULT hr = pHttpRequest->SetHttpMethod("OPTIONS");
// Test for an error.
if (FAILED(hr))
{
// Set the error status.
pProvider->SetErrorStatus( hr );
// End additional processing.
return RQ_NOTIFICATION_FINISH_REQUEST;
}
}
// Return processing to the pipeline.
return RQ_NOTIFICATION_CONTINUE;
}
};
// 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
);
}
Requisitos
Type | 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 |