Use httphandler to monitor HTML page requests

Source: Internet
Author: User
Tags url forwarding

AIis7Bottom pureHtmlThe page request source for many reasons: 

    • Multiple independent domain names are bound to oneWebsite
    • Domain Name vendor not supportedURL forwarding
    • Automatically after the domain name is enteredRedirectTo the primary domain name, such:
    • InputWww.ccc.netLaterRedirectToWww.aaa.com
    • InputWww.ddd.cnLaterRedirectToWww.aaa.com

 

So I tried to make an HTML handler.

 

Steps:

 

  1. Set the target website'sApplication poolThe mode isIntegrate
  2. Write. NET 2.0OfHttphandlerTo process requests(Here is*. HtmlFile request)
  3. Public Class Urlverify: ihttphandler
    {
    Public Bool Isreusable
    {
    Get { Return True ;}
    }

    Const String Mainhostname = " Www.aaa.com " ;
    Public Void Processrequest (httpcontext context)
    {
    If (Context. Request. url. Host. tolower ()! = Mainhostname)
    {
    String Url = generatemainsiteurl (context. Request. url. absoluteuri, context. Request. rawurl );
    Context. response. Redirect (URL, True );
    }
    Else
    {
    Context. response. writefile (context. Request. physicalpath );
    }
    }

    Public String Generatemainsiteurl ( String Fullurl, String Virtualpath)
    {
    String Url = fullurl;
    String Preurl = " HTTP " ;
    If (URL. substring ( 0 , 5 ). Tolower () = " HTTPS " )
    Preurl = " HTTPS " ;

    Virtualpath = virtualpath. trimstart ('/');

    Url =String. Format ("{0}: // {1}/{2}", Preurl, mainhostname, virtualpath );
    ReturnURL;
    }
    }

  4. After the compiledDLLFiles are stored on the target websiteBinDirectory
  5. OpenIis7,Find the target website and double-clickHandler MappingsIcon
  6. In the upper-right cornerClick Add managed HandlerLink
  7. OK

 

 

Confused:

The above components are used. Net2.0Compiled, I use. Net4.0I tried it, but I always reported an error. I don't know what's going on. I hope my experienced brother will tell me.

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.