[英]IIS 6 Isapi filter - forward or redirect requets to other domain
A code bellow is main part of my Isapi filter for IIS 6. I need to redirect all request which contains "/some_string" to other url, which lies on other domain and other server. 下面的代码是我的IIS 6 Isapi筛选器的主要部分。我需要将所有包含“ / some_string”的请求重定向到位于其他域和其他服务器上的其他URL。 How to do it? 怎么做?
DWORD CAmgnIsapiFilter::OnPreprocHeaders(CHttpFilterContext* pCtxt,
PHTTP_FILTER_PREPROC_HEADERS pHeaderInfo)
{
char buffer[256];
DWORD buffSize = sizeof(buffer);
BOOL bHeader = pHeaderInfo->GetHeader(pCtxt->m_pFC, "url", buffer, &buffSize);
CString urlString(buffer);
urlString.MakeLower();
if (urlString.Find("/some_string") != -1) //we want to redirect this file
{
urlString.Replace("/some_string","");
urlString = "http://new_domain.cz/something" + urlString;
char * newUrlString= urlString.GetBuffer(urlString.GetLength());
pHeaderInfo->SetHeader(pCtxt->m_pFC, "url", newUrlString);
return SF_STATUS_REQ_HANDLED_NOTIFICATION;
}
//we want to leave this alone and let IIS handle it
return SF_STATUS_REQ_NEXT_NOTIFICATION;
}
Thanks! 谢谢!
You need to respond with a 302 status code, telling the browser which is the new URL you want to redirect to. 您需要使用302状态代码进行响应,告诉浏览器您要重定向到的新URL。
Just a small, not production-grade template to achieve this: 只是一个小的而非生产级的模板即可实现此目的:
//... char rsp[50]; // ... char rsp [50]; wsprintf(rsp, "Location: %s\\r\\n\\r\\n", newUrlString); wsprintf(rsp,“位置:%s \\ r \\ n \\ r \\ n”,newUrlString); pfc->ServerSupportFunction (pfc, SF_REQ_SEND_RESPONSE_HEADER, (PVOID) "302 Redirect", (DWORD) rsp, 0); pfc-> ServerSupportFunction(pfc,SF_REQ_SEND_RESPONSE_HEADER,(PVOID)“ 302重定向”,(DWORD)rsp,0); //... // ...
instead of 代替
pHeaderInfo->SetHeader(pCtxt->m_pFC, "url", newUrlString); pHeaderInfo-> SetHeader(pCtxt-> m_pFC,“ url”,newUrlString);
I think this is the only thing you have to do. 我认为这是您唯一要做的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.