CHttpModule::OnMapPath 方法
表示將處理 MapPath
事件的方法,當作業要求對應至目前要求的實體路徑時,就會發生此事件。
語法
virtual REQUEST_NOTIFICATION_STATUS OnMapPath(
IN IHttpContext* pHttpContext,
IN IMapPathProvider* pProvider
);
參數
pHttpContext
[IN] IHttpCoNtext 介面的指標。
pProvider
[IN] IMapPathProvider 介面的指標。
傳回值
備註
當要求層級模組註冊 RQ_MAP_PATH 通知時,當作業要求實體路徑對應至目前要求時,IIS 會呼叫模組 OnMapPath
的 方法。
注意
要求層級模組可以在模組的RegisterModule函式中註冊 ,以註冊 MapPath
RQ_MAP_PATH
事件通知。
範例
下列程式碼範例示範如何建立註冊事件通知的要求層級 HTTP 模組 RQ_MAP_PATH
。 當作業要求對應目前要求的實體路徑時,IIS 會呼叫範例模組的 OnMapPath
方法。
// Insert data from ostringstream into the response
// On error, Provider error status set here
// ostringstream buffer cleared for next call
HRESULT WECbyRefChunk( std::ostringstream &os, IHttpContext *pHttpContext,
IHttpEventProvider *pProvider, LONG InsertPosition= -1)
{
HRESULT hr = S_OK;
IHttpTraceContext * pTraceContext = pHttpContext->GetTraceContext();
hr = pTraceContext->QuickTrace(L"WECbyRefChunk",L"data 2",E_FAIL,6);
if (FAILED(hr)){
LOG_ERR_HR(hr,"QuickTrace");
return hr;
}
// create convenience string from ostringstream
std::string str(os.str());
HTTP_DATA_CHUNK dc;
dc.DataChunkType = HttpDataChunkFromMemory;
dc.FromMemory.BufferLength = static_cast<DWORD>(str.size());
dc.FromMemory.pBuffer = pHttpContext->AllocateRequestMemory(
static_cast<DWORD>( str.size()+1) );
if(!dc.FromMemory.pBuffer){
hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
LOG_ERR_HR(hr,"AllocateRequestMemory");
pProvider->SetErrorStatus(hr);
return hr;
}
// use char pointer p for convenience
char *p = static_cast<char *>(dc.FromMemory.pBuffer);
strcpy_s(p, str.size()+1, str.c_str());
hr = pHttpContext->GetResponse()->WriteEntityChunkByReference(
&dc, InsertPosition );
if (FAILED(hr)){
LOG_ERR_HR(hr,"AllocateRequestMemory");
pProvider->SetErrorStatus( hr );
}
os.str(""); // clear the ostringstream for next call
return hr;
}
規格需求
類型 | 描述 |
---|---|
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 |