IHttpRequest::SetUrl 메서드
요청 URL을 수정합니다.
구문
virtual HRESULT SetUrl(
IN PCWSTR pszUrl,
IN DWORD cchUrl,
IN BOOL fResetQueryString
) = 0;
virtual HRESULT SetUrl(
IN PCSTR pszUrl,
IN DWORD cchUrl,
IN BOOL fResetQueryString
) = 0;
매개 변수
pszUrl
[IN] 설정할 URL이 포함된 문자열에 대한 포인터입니다.
cchUrl
[IN] 로 지정된 pszUrl
URL의 길이(문자)입니다.
fResetQueryString
[IN] true
기존 쿼리 문자열을 다시 설정하려면 이고, 그렇지 않으면 입니다 false
.
반환 값
HRESULT
입니다. 가능한 값에는 다음 표에 있는 값이 포함되지만, 이에 국한되는 것은 아닙니다.
값 | 설명 |
---|---|
S_OK | 작업이 성공했음을 나타냅니다. |
ERROR_INVALID_PARAMETER | 지정된 매개 변수가 유효하지 않음을 나타냅니다(예: 지정된 URL이 너무 깁니다). |
ERROR_NOT_ENOUGH_MEMORY | 작업을 수행할 메모리가 부족했음을 나타냅니다. |
설명
메서드는 SetUrl
현재 요청에 대한 URL을 수정합니다. 메서드의 오버로드된 버전이 두 개 있습니다 SetUrl
. 하나를 사용하면 문자열에 대한 포인터를 사용하여 헤더를 지정할 수 있습니다. 다른 오버로드는 와이드 문자열에 대한 포인터를 사용합니다.
후속 요청 처리 함수 및 로깅 작업은 클라이언트가 URL을 요청한 것처럼 새 URL을 처리합니다. 따라서 URL 수정으로 인한 오류 조건은 클라이언트에 반환됩니다. 예를 들어 새 URL이 없는 경우 웹 서버는 HTTP 404 오류를 반환합니다.
경고
메서드는 SetUrl
요청에 대한 초기 매개 변수가 수집된 후에 호출되므로 후속 요청 처리에서 변경된 URL을 인식하지 못할 수 있습니다. 예를 들어 URL 서버 변수를 검색하면 변경된 URL이 아니라 원래 요청이 반영됩니다. 구현자는 전체 파이프라인을 통해 요청을 실행하기 위해 대신 SetUrl
IHttpContext::ExecuteRequest 메서드를 호출해야 합니다. 메서드는 SetUrl
URL 다시 쓰기에 사용하면 안 됩니다.
참고
IHttpResponse::Redirect 메서드 SetUrl
와 달리 메서드는 클라이언트를 새 URL로 리디렉션하지 않습니다.
참고
HTTP 통합 요청 처리 파이프라인에서 첫 번째 이벤트 전에 메서드를 호출 SetUrl
해야 합니다. SetUrl
OnPostBeginRequest 처리기에서 메서드를 호출하면 확정되지 않은 동작이 발생합니다.
예
다음 코드 예제를 사용 SetUrl
하는 방법에 설명 합니다 요청 된 URL을 다른 URL로 변경 하는 방법입니다.
#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
)
{
HRESULT hr;
// Retrieve a pointer to the request.
IHttpRequest * pHttpRequest = pHttpContext->GetRequest();
// Test for an error.
if (pHttpRequest != NULL)
{
// Create a buffer with an example URL.
PCSTR pszBuffer = "/example/default.aspx";
// Set the URL for the request.
hr = pHttpRequest->SetUrl(
pszBuffer,(DWORD)strlen(pszBuffer),true);
// 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 - IIS 8.0 on Windows Server 2012 - 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 |