IHttpTraceCoNtext::QuickTrace 方法
將訊息寫入 IIS 追蹤記錄。
語法
virtual
HRESULT
QuickTrace(
IN PCWSTR pszData1,
IN PCWSTR pszData2 = NULL,
IN HRESULT hrLastError = S_OK,
IN UCHAR Level = 4
) = 0;
參數
參數 | 描述 |
---|---|
pszData1 |
要記錄的訊息。 |
pszData2 |
要記錄的第二則訊息。 |
hrLastError |
要記錄的 HRESULT 。 預設值為 S_OK。 |
level |
追蹤層級。 可能的值為 1 到 7。 預設值為 4 (TRACE_LEVEL_INFORMATION) 。 如需詳細資訊,請參閱<備註>一節。 |
傳回值
HRESULT
。 可能的值包括 (但不限於) 下表中的這些值。
值 | 描述 |
---|---|
S_OK | 表示作業成功。 |
備註
事件追蹤層級 1 到 5 對應至 Windows 事件追蹤 (ETW) 追蹤層級。 如需這些追蹤層級的詳細資訊,請參閱 EVENT_TRACE_HEADER 結構。 您也可以使用 HTTPtrace.h 頭) 檔中定義為 HTTP_TRACE_LEVEL_START 的追蹤層級 6 (,以及 HTTPtrace.h) 中定義為HTTP_TRACE_LEVEL_END的追蹤層級 7 (。
範例
下列範例示範如何使用 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
);
}
規格需求
類型 | 描述 |
---|---|
Client | - 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 |