The following code demonstrates how to use an OnUrlMap notification in the filter to redirect a request to a different URL. If the URL contains a DoRedirect string (for example, http://server/doRedirect), the request will be redirected to http://www.microsoft.com.
DWORD CFiltRedirFilter::OnUrlMap(CHttpFilterContext* pCtxt,
PHTTP_FILTER_URL_MAP pMapInfo)
{
CHAR szRedirect [256];
if (strstr (pMapInfo->pszURL, "DoRedirect"))
{
CHAR szRedirect [256];
// replace www.microsoft.com with desired server
sprintf(szRedirect, "Location: http://%s\r\n\r\n", "www.microsoft.com");
pCtxt->ServerSupportFunction ( SF_REQ_SEND_RESPONSE_HEADER,
(LPVOID) "302 Redirect",
(DWORD *) szRedirect,
0 );
// Print a message to the debug window
ISAPITRACE1 ("Redirecting to: %s\n", szRedirect);
// we are done with this request
return SF_STATUS_REQ_FINISHED_KEEP_CONN;
}
// URL did not contain a DoRedirect string.
return SF_STATUS_REQ_NEXT_NOTIFICATION;
}