isapi中的一個轉向例子

來源:互聯網
上載者:User

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_HTTP All HTTP headers that were not already parsed into one of the above variables. These variables are of the form HTTP_<header field name>.
AUTH_TYPE Contains 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_LENGTH The number of bytes which the script can expect to receive from the client.
CONTENT_TYPE The content type of the information supplied in the body of a POST request.
GATEWAY_INTERFACE The revision of the CGI specification to which this server complies. The current version is CGI/1.1.
HTTP_ACCEPT Special 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.1accept: text/htmlaccept: image/jpeg

then the HTTP_ACCEPT variable will have a value of:

*/*; q=0.1, text/html, image/jpeg
PATH_INFO Additional 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_TRANSLATED This is the value of PATH_INFO, but with any virtual path name expanded into a directory specification.
QUERY_STRING The information which follows the ? in the URL which referenced this script.
REMOTE_ADDR The IP address of the client.
REMOTE_HOST The hostname of the client.
REMOTE_USER This contains the username supplied by the client and authenticated by the server.
REQUEST_METHOD The HTTP request method.
SCRIPT_NAME The name of the script program being executed.
SERVER_NAME The server's hostname (or IP address) as it should appear in self-referencing URLs.
SERVER_PORT The TCP/IP port on which the request was received.
SERVER_PROTOCOL The name and version of the information retrieval protocol relating to this request. Normally HTTP/1.0.
SERVER_SOFTWARE The name and version of the web server under which the CGI program is running.

 

會發現其實都是一樣的

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.