isapi中的一个转向例子

DWORD CUrltest1Filter::OnUrlMap(CHttpFilterContext* pCtxt,
 PHTTP_FILTER_URL_MAP pMapInfo)
{
 // TODO: React to this notification accordingly and
 // return the appropriate status code
 char buffer[1024];
 DWORD bufferSize=sizeof(buffer);
 pCtxt->GetServerVariable("SERVER_NAME", buffer, &bufferSize);
//  if (strstr (pMapInfo->pszURL, "DoRedirect"))
  if (strstr (buffer, "localhost"))
   {
      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;
}

不同于我上一篇isapi的写法用了 pCtxt->GetServerVariable("SERVER_NAME", buffer, &bufferSize);
GetServerVariable其实与asp的Request.ServerVariable是一个例子,参考msdn中的

ALL_HTTPAll HTTP headers that were not already parsed into one of the above variables. These variables are of the form HTTP_<header field name>.
AUTH_TYPEContains the type of authentication used.  For example, if Basic authentication is used, the string will be "Basic". For Windows NT Challenge-response, it will be "NTLM". Other authentication schemes will have other strings. Because new authentication types can be added to Internet Server, it is not possible to list all possible strings. If the string is empty then no authentication is used.
CONTENT_LENGTHThe number of bytes which the script can expect to receive from the client.
CONTENT_TYPEThe content type of the information supplied in the body of a POST request.
GATEWAY_INTERFACEThe revision of the CGI specification to which this server complies. The current version is CGI/1.1.
HTTP_ACCEPTSpecial case HTTP header. Values of the Accept: fields are concatenated, separated by ", ". For example, if the following lines are part of the HTTP header:
accept: */*; q=0.1
accept: text/html
accept: image/jpeg

then the HTTP_ACCEPT variable will have a value of:

*/*; q=0.1, text/html, image/jpeg
PATH_INFOAdditional path information, as given by the client. This comprises the trailing part of the URL after the script name but before the query string (if any).
PATH_TRANSLATEDThis is the value of PATH_INFO, but with any virtual path name expanded into a directory specification.
QUERY_STRINGThe information which follows the ? in the URL which referenced this script.
REMOTE_ADDRThe IP address of the client.
REMOTE_HOSTThe hostname of the client.
REMOTE_USERThis contains the username supplied by the client and authenticated by the server.
REQUEST_METHODThe HTTP request method.
SCRIPT_NAMEThe name of the script program being executed.
SERVER_NAMEThe server's hostname (or IP address) as it should appear in self-referencing URLs.
SERVER_PORTThe TCP/IP port on which the request was received.
SERVER_PROTOCOLThe name and version of the information retrieval protocol relating to this request. Normally HTTP/1.0.
SERVER_SOFTWAREThe name and version of the web server under which the CGI program is running.

 

会发现其实都是一样的

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值