Asp.net rewrite urlrewriter with URL to implement any second-level domain name on page 1/2

Source: Internet
Author: User

No writing technology for a long time Article If you do not understand, read more articles, sweat, or reply after the article (this is the most effective method). I will try my best to help you answer your questions.

I should know what a second-level domain name is when I come to this article, so I won't talk nonsense. But before the discussion, I should first understand an ideological problem.
The problem that many of my friends have been confused (I have been confused a few days ago) is that after I type an address, how can this URL be rewritten?
Step 1: What happened when I typed an address in a browser, such as a http://love.kerry.com, and clicked enter?
To simplify the problem, I will explain it as follows:
Step 2: first, the entered address is parsed and finally comes to a Web server. to IIS for processing. in. in the net world, IIS will send such requests to a web processor for processing. Finally, the Web processor returns the processing results to the browser and displays them to users.
Please do not ignore this problem. Everything in step 2 is done on the server side. during these operations, the address on the browser of the user side will not change. even if the web processor returns the processing result, the above address will not change.
The URL entered at the beginning serves only as a knock-on interface. After the door is knocked out, the function is completed. Only your eyes can see the address, the browser, the server does not know the address.
The problem that we need to understand is that URL rewriting is only an insider situation that web developers know, and users do not know what happened, he thinks that the address he typed is the result displayed on the screen. that is to say, we control the content to be displayed behind the scenes.
Next, we should consider how to control the displayed content?
From the process mentioned above, it is obvious that you need to work in the Web processor step.

One of the simplest considerations is that the user typed in a simple address without any parameters, http://love.kerry.com then we changed this address toProgramRequired address with parameters, http://kerry.com? Lover = notus.
This step is called URL rewriting.
In. Net terminology, We need to register an httpmodule for the application to process specific URLs.
Register httpmodule, in Web. config,
Processing URL, In the httpmodule program we provide

It is basically equivalent to a program like this.

// Use our httpmodule program to capture the original URL
String originalurl = "http://love.kerry.com ";
// Process the original URL and get the final required URL. The value is http://kerry.com? Lover = notus
String finalurl = rewrite (originalurl );
// Context re-sends the URL internally to IIS for processing
Context. rewritepath (finalurl );

Next, we will rewrite the URL.
Step 1: Determine the URLs to be overwritten, that is, the rewrite rules.
Step 2: Compile the httpmodule Handler
Step 3: Integrate the compiled httpmodule into the web program and start working.

The above is the basic knowledge of URL rewriting, and the process of using URL rewriting to implement second-level domain names is the same. because both the second-level domain name and third-level domain name are URLs. as long as we intercept this URL address, we can start to process it.

These jobs are troublesome, but some people on the Internet have written such a program for us. refer to the following article:

Http://www.microsoft.com/china/msdn/library/webservices/asp.net/URLRewriting.mspx

Http://www.cnblogs.com/jzywh/archive/2005/09/29/246650.html

Http://www.cnblogs.com/jzywh/archive/2006/02/20/334004.html

The article is over.

Some problems may occur during the implementation process, mostly because the above articles are not carefully produced, but to be honest, it is not easy to read long articles. below I will record some important issues. for the last two questions, use the specificCodeDemonstrate how to rewrite the target URL to meet our requirements

Why do I have to use wildcard parsing?
After reading replies from many friends, I think there may be such a misunderstanding: This article on URL rewriting only introduces some processing methods. it is not important that pan resolution is not pan resolution.
If you do not need to implement any second-level domain name, you do not need to implement Pan resolution. You can directly fix the second-level domain name you need, and then process it in URL rewriting!
Further, if you do not need to implement a second-level domain name, but simply rewrite the URL under a fixed domain name, you do not need to modify the urlrewriter of msdn, simple URL rewriting can be implemented directly. zyw only makes modifications to this project to get all the URLs for greater control. as we can see, the urlrewriter at the beginning of msdn does not care about Domain Name issues.
I wrote this article at the beginning because I recently used it in my project.

What is Microsoft's urlrewriter? Where can I download this project?
This is the sample program provided in the previous article about urlrewriter on msdn. You can download it here
Http://www.microsoft.com/china/msdn/library/webservices/asp.net/URLRewriting.mspx

How to use the code? Trouble?
Certainly, it is not troublesome. The following things are to be done:
Download the code to your machine.
After installation, add the urlrewriter project to your project.
Modify the code according to the method in the address given above
Configure web. config to start using.

What is httpmodule?

Simply put, it is a program that processes HTTP requests.
For more information, see the SDK documentation.

How to Implement Pan resolution?

First, add a second-level domain name * .kerry.com to the Domain Name Service Provider, pointing to your server IP address.
Then, create a site in IIS. The Host Header of this site is left blank, and the port is usually 80. This site is the default website of port 80 on the server.
Add a wildcard application ing (IIS Site Properties> main directory> Configuration) to the site ), the purpose of this ing is to require Asp.net ISAPI to take over any second-level domain site that is not explicitly defined in IIS.

What happens when I enter a second-level domain name?
When IIS detects that the input URL is a second-level domain name, it first checks whether there is a site registered with this second-level domain name on IIS. If yes, It is transferred to this site. Otherwise, the default site is the site with the Host Header empty. therefore, a port can only have a site with an empty Host header.
We have set up Asp.net ISAPI to take over these children who do not have a home. Write the program, analyze the passed URL, and rewrite the program.

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.