CHttpServer::RedirectRequest Method  
 
BOOL RedirectRequest(
  UINT nClientId,  
  UINT nMethod,  
  LPCTSTR lpszLocation  
);

Redirect the request from the client to another URL.

Parameters

nClientId
An unsigned integer which uniquely identifies the client session.
nMethod
An integer value that specifies if the redirection is permanent or temporary. The following values may be used:
Value Description
HTTP_REDIRECT_PERMANENT This value is used for permanent redirection, indicating that the client should update any record of the link with the new URL specified by the lpszLocation parameter. This result is cacheable and when the client makes subsequent requests for the resource, it should always use the new URL.
HTTP_REDIRECT_TEMPORARY This value is used for temporary redirection, indicating that the client should issue a request for the resource using the new URL specified by the lpszLocation parameter, but subsequent requests should continue to use the original URL.
HTTP_REDIRECT_OTHER This value is used for temporary redirection, however it instructs the client that it should use the GET command to request the redirected resource. This option is typically used to redirect a client after it has used the POST command.
lpszLocation
A null-terminated string that specifies the new location for the requested resource. This value must be a complete URL, including the http:// or https:// scheme. This parameter cannot be NULL or point to zero-length string.

Return Value

If the method succeeds, the return value is non-zero. If the method fails, the return value is zero. To get extended error information, call the GetLastError method.

Remarks

The RedirectRequest method can be used within a HTTP_CLIENT_COMMAND event handler to redirect the client to a new location for the resource that it has requested. This redirection can be permanent or temporary, depending on whether the server expects the client to continue to use the original URL when requesting the resource.

If the HTTP_REDIRECT_TEMPORARY method is used, the actual status code that is returned to the client depends on the version of the protocol that is being used. If the client has issued the request using HTTP 1.0 then the server will return a 302 code to the client. If the client is using HTTP 1.1, the server will return a 307 code to the client that indicates it should use the same command verb (GET, POST, etc.) when requesting the resource at the new location.

If the HTTP_REDIRECT_OTHER method is used, the status code that is returned to the client depends on which version of the protocol is being used. For clients who are using HTTP 1.0, the server will return a 302 code to the client just as with the HTTP_REDIRECT_TEMPORARY method. If the client is using HTTP 1.1, the server will return a 303 code to the client that indicates it should always use the GET command to request the new resource, regardless if a different command was originally used (POST, PUT, etc.)

This method provides a simplified interface for sending a redirection status code that also implicitly sets the Location response header to the value of the lpszLocation parameter. If the server application needs to send alternate redirection codes such as 305 (Use Proxy) then it should use the SendReponse method.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools11.h
Import Library: cshtsv11.lib
Unicode: Implemented as Unicode and ANSI versions

See Also

RequireAuthentication, SendErrorResponse, SendResponse