IHttpServer::GetFileInfo 메서드
특정 파일 경로에 대한 IHttpFileInfo 인터페이스를 반환합니다.
구문
virtual HRESULT GetFileInfo(
IN PCWSTR pszPhysicalPath,
IN HANDLE hUserToken,
IN PSID pSid,
IN PCWSTR pszVrPath,
IN HANDLE hVrToken,
IN BOOL fCache,
OUT IHttpFileInfo** ppFileInfo,
IN IHttpTraceContext* pHttpTraceContext = NULL
) = 0;
매개 변수
pszPhysicalPath
[IN] 파일의 실제 경로를 포함하는 문자열에 대한 포인터입니다.
hUserToken
[IN] HANDLE
가장 사용자에 대한 토큰이 들어 있는 이며, 그렇지 않으면 NULL입니다.
pSid
[IN] 가장 사용자의 보안 ID를 포함하는 SID(보안 식별자)에 대한 포인터입니다. 그렇지 않으면 NULL입니다.
pszVrPath
[IN] 변경 알림을 등록할 가상 경로가 포함된 문자열에 대한 포인터입니다. 그렇지 않으면 NULL입니다.
hVrToken
[IN] HANDLE
변경 알림에 등록할 가장 토큰이 들어 있는 이며, 그렇지 않으면 NULL입니다.
fCache
[IN] true
파일을 캐시해야 함을 나타내려면 입니다. 그렇지 않으면 입니다 false
.
ppFileInfo
[OUT] 인터페이스에 대한 역참조 포인터입니다 IHttpFileInfo
.
pHttpTraceContext
[IN] 선택적 IHttpTraceContext 인터페이스에 대한 포인터입니다.
반환 값
HRESULT
입니다. 가능한 값에는 다음 표에 있는 값이 포함되지만, 이에 국한되는 것은 아닙니다.
값 | 정의 |
---|---|
S_OK | 작업이 성공했음을 나타냅니다. |
E_FAIL | 모듈 호스트가 종료되는 동안 에 GetFileInfo 대한 호출이 이루어졌다는 것을 나타냅니다. |
설명
메서드는 IHttpServer::GetFileInfo
특정 경로에 IHttpFileInfo
대한 인터페이스를 만듭니다. 이 메서드는 IIS가 요청 컨텍스트 내에서 처리 중인 파일에 대한 인터페이스를 반환 IHttpFileInfo
하는 IHttpContext::GetFileInfo 메서드와 다릅니다.
pszPhysicalPath
및 ppFileInfo
매개 변수는 인터페이스를 만드는 IHttpFileInfo
데 필요합니다. 매개 변수는 pszPhysicalPath
파일의 경로를 지정하고 매개 변수는 ppFileInfo
IIS가 해당 IHttpFileInfo
인터페이스로 채울 포인터를 정의합니다.
및 hVrToken
매개 변수는 pszVrPath
선택 사항이며 사용하지 않는 경우 NULL로 설정해야 합니다. 이러한 매개 변수는 모듈이 변경 알림을 등록할 때 사용할 가상 경로 및 가장 토큰을 각각 지정합니다(예: 매개 변수true
를 로 설정 fCache
하여 캐싱을 요청하는 경우).
참고
매개 변수에 대해 fCache
를 지정 true
하더라도 다른 구성 설정으로 인해 IIS에서 파일을 캐싱하지 못할 수 있습니다.
hUserToken
및 pSid
매개 변수도 선택 사항이며 사용하지 않는 경우 NULL로 설정해야 합니다. 이러한 매개 변수는 각각 가장 사용자에 대한 토큰 및 SID를 지정합니다. 나머지 선택적 매개 변수인 pHttpTraceContext
는 추적을 IHttpTraceContext
위한 인터페이스를 지정합니다.
예제
다음 코드 예제에서는 다음 작업을 수행하는 HTTP 모듈을 만드는 방법을 보여 줍니다.
RQ_BEGIN_REQUEST 알림을 등록합니다.
OnBeginRequest 메서드를 포함하는 CHttpModule 클래스를 만듭니다. 클라이언트가 파일을 요청하면 메서드는
OnBeginRequest
다음 작업을 수행합니다.IHttpContext::MapPath 메서드를 사용하여 경로를 상대 URL에 매핑합니다.
메서드를
IHttpFileInfo
사용하여 파일 경로에 대한 인터페이스를IHttpServer::GetFileInfo
만듭니다.IHttpFileInfo::GetETag 메서드를 사용하여 파일에 대한 엔터티 태그를 검색합니다.
IHttpResponse::WriteEntityChunks 메서드를 사용하여 엔터티 태그를 클라이언트에 반환합니다.
메모리에서 클래스를
CHttpModule
제거한 다음 종료합니다.
#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <httpserv.h>
// Create a pointer for the global server interface.
IHttpServer * g_pHttpServer = NULL;
// Create the module class.
class MyHttpModule : public CHttpModule
{
public:
REQUEST_NOTIFICATION_STATUS
OnBeginRequest(
IN IHttpContext * pHttpContext,
IN IHttpEventProvider * pProvider
)
{
UNREFERENCED_PARAMETER( pProvider );
HRESULT hr;
PWSTR wszUrl = L"/example/default.asp";
WCHAR wszPhysicalPath[1024] = L"";
DWORD cbPhysicalPath = 1024;
pHttpContext->MapPath(wszUrl,wszPhysicalPath,&cbPhysicalPath);
if (NULL != wszPhysicalPath)
{
IHttpFileInfo * pHttpFileInfo;
hr = g_pHttpServer->GetFileInfo(wszPhysicalPath,
NULL,NULL,wszUrl,NULL,TRUE,&pHttpFileInfo);
if (NULL != pHttpFileInfo)
{
// Create a buffer for the Etag.
USHORT cchETag;
// Retrieve the Etag.
PCSTR pszETag = pHttpFileInfo->GetETag(&cchETag);
//Test for an error.
if (NULL != pszETag)
{
// 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 the Etag to the client.
WriteResponseMessage(pHttpContext,
"ETag: ",pszETag);
// End additional processing.
return RQ_NOTIFICATION_FINISH_REQUEST;
}
}
}
// Return processing to the pipeline.
return RQ_NOTIFICATION_CONTINUE;
}
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 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 );
// Store the pointer for the global server interface.
g_pHttpServer = pGlobalInfo;
// Set the request notifications and exit.
return pModuleInfo->SetRequestNotifications(
new MyHttpModuleFactory,
RQ_BEGIN_REQUEST,
0
);
}
네이티브 DLL 모듈을 만들고 배포하는 방법에 대한 자세한 내용은 연습: 네이티브 코드를 사용하여 Request-Level HTTP 모듈 만들기를 참조하세요.
필요에 따라 각 함수에 대한 호출 규칙을 명시적으로 선언하는 대신 호출 규칙을 사용하여 __stdcall (/Gz)
코드를 컴파일할 수 있습니다.
요구 사항
형식 | 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 |