IHttpTraceContext::QuickTrace 메서드
IIS 추적 로그에 메시지를 씁니다.
구문
virtual
HRESULT
QuickTrace(
IN PCWSTR pszData1,
IN PCWSTR pszData2 = NULL,
IN HRESULT hrLastError = S_OK,
IN UCHAR Level = 4
) = 0;
매개 변수
매개 변수 | Description |
---|---|
pszData1 |
기록할 메시지입니다. |
pszData2 |
기록할 두 번째 메시지입니다. |
hrLastError |
기록할 입니다 HRESULT . 기본값은 S_OK. |
level |
추적 수준입니다. 가능한 값은 1~7입니다. 기본값은 4(TRACE_LEVEL_INFORMATION)입니다. 자세한 내용은 주의 섹션을 참조하세요. |
반환 값
HRESULT
입니다. 가능한 값에는 다음 표에 있는 값이 포함되지만, 이에 국한되는 것은 아닙니다.
값 | 설명 |
---|---|
S_OK | 작업이 성공했음을 나타냅니다. |
설명
이벤트 추적 수준 1~5는 ETW(Windows용 이벤트 추적) 추적 수준에 해당합니다. 이러한 추적 수준에 대한 자세한 내용은 EVENT_TRACE_HEADER 구조를 참조하세요. 추적 수준 6(Httptrace.h 헤더 파일에서 HTTP_TRACE_LEVEL_START 정의됨) 및 추적 수준 7(Httptrace.h에서 HTTP_TRACE_LEVEL_END 정의됨)을 사용할 수도 있습니다.
예제
다음 예제에서는 IHttpRequest::SetUrl 메서드를 사용하여 요청된 URL을 다른 URL로 변경하고 메서드를 사용하여 변경 사항을 QuickTrace
기록하는 방법을 보여 줍니다.
이벤트를 보려면 실패한 이벤트 요청 추적을 사용하도록 설정해야 합니다.
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
);
}
요구 사항
형식 | 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 |