Vc6 uses ISAPI filter to implement URL redirection

Source: Internet
Author: User

Using VC to implement URL redirection is very simple. Of course, using. NET is simpler, but asp3 does not use the. NET method. This kind of technology is required in recent work.

I recently referred to Chapter 5 Microsoft Internet Information Server (IIS) programming in the fifth edition of Visual C ++ technology. Some ISAPI technologies are mentioned in it, but there is little talk about filters in it, it is hard to understand how to use URL rewriter Technology

However, in practice, I found a very interesting word onurlmap. At that time, I guess this overload function can implement redirection? So I opened the msdn manual and searched for it and found that it was okay. Now let's talk about it.Code

First, create a project in vc6-> select ISAPI extension wizard-> select ISAPI filter, and then check the extension of the following ISAPI-> in addition to the check of the default options, you must add a URL Mapping requests check.

In the onurlmap function, enter
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;

Generate DLL. Select the DLL in the ISAPI filter in the properties of the default website in IIS.

Then, enter http: // localhost/doredirect in IE or other web browsers. Then what do you see? That's right. It's Microsoft's homepage.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.