asp.net use URL rewrite urlrewriter to implement any level two domain name 1th/2 Page _ Practical Tips

Source: Internet
Author: User
Tags iis server port
For a long time did not write technical articles, if you do not understand, see more than a few, Khan, or, in the back of the article (this is the most effective way), I will try to help everyone to answer questions.

To find this article, should know what is called the level two domain name, nonsense will not say. But before we talk, we need to understand a question of thought.
A lot of friends have been thinking about (I have been confused the last few days) The question is, I typed an address, how the URL has been rewritten?
The first step: in the browser type an address, such as http://love.kerry.com, after the point of return, what happened?
To simplify the problem, let me explain this:
Step two: First, the address that you typed is parsed, and eventually comes to a Web server. To IIS. In the. NET world, IIS will send such a request to a web processor, and finally, the Web processor returns the results of the processing to the browser, which is displayed to the user.
You don't have to ignore this, and everything in the second step is done on the server side. When these things go on, the address on the client's browser does not change. Even if the last Web processor returns the processing results, the address above will not change.
At the beginning of the URL to type, just a knock on the role of the door, the effect even if the end, only your eyes can see that address, browser, server and so do not know this address.
The problem, then, is that the so-called URL rewrite is just the insider information the web Developer knows, and the user has no idea what's going on, and he thinks he's typing the address that should come out of the screen. In other words, we control what we want to display behind the scenes.
The next thing to consider is, how to control the display of content?
From the above process, it is clear that the work of the Web processor is a step in the foot.

One of the simplest considerations is that the user has typed a simple, http://love.kerry.com address, and then we'll change the address to a parameter-compliant address that meets the needs of the program, Http://kerry.com?lover=notus, The final deal.
The so-called URL rewrite is in this step.
In the. NET terminology, we need to register a httpmodule for the application to handle a particular URL
Registered HttpModule, in web.config,
Processing URLs, in the HttpModule program we provide

Roughly equivalent to a procedure like this

Intercept the original URL with our HttpModule program
String originalurl= "http://love.kerry.com";
Process the original URL, get the last required URL, the value is Http://kerry.com?lover=notus
String Finalurl=rewrite (Originalurl);
The context sends the URL internally to IIS for processing
Context. RewritePath (FinalURL);

Next, we'll implement URL rewriting.
Step one: Determine which URLs you want to override, that is, make the rewrite rules
Step two: Write the HttpModule handler
Step three: Integrate the written httpmodule into the Web program and start working.

The above is the basic knowledge of URL rewriting, and using URL rewrite to achieve level two domain name, the process is the same. Because whether it is a level two domain name or a level three domain name, is a URL address. As long as we intercept this URL, we can do it at the time of processing.

These jobs are very troublesome, but the internet has a high man to write us this program, see 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.

There will be some problems in the implementation process, mostly because look at the above article is not carefully produced, but to tell the truth, so long articles to read it is not easy. Let me write down some important questions. The last two questions, with specific code showing how to handle the overridden target URL to meet our requirements


Why do I have to use a pan-parsing?
Read a lot of friends reply, I think now there may be such a misunderstanding, that is, this article on the URL rewrite is just to introduce some of the processing methods. It doesn't matter if the pan-resolution doesn't pan-parse.
If you do not need to implement any two-level domain name, it is not necessary to implement the pan-resolution, directly to the level of the two domain name you need to die, and then in the URL rewrite to deal with it!
Step back, if even the two-level domain name does not need to be implemented, just a fixed domain name under the URL to rewrite, that does not need to modify the MSDN Urlrewriter, directly to use it can achieve a simple URL rewrite. Zyw's changes to the project are only for greater control over the entire URL. And as we've seen, the first MSDN Urlrewriter doesn't care about domain names.
I started with this topic because I used it recently in my project and wrote it when I was writing the document.



What is the urlrewriter of Microsoft and where is this project downloaded?
This is the sample program that is available in the MSDN previous article on Urlrewriter, where you can download
Http://www.microsoft.com/china/msdn/library/webservices/asp.net/URLRewriting.mspx


How do you use this code?
Sure, no trouble, there are things to be done:
Download the code to your machine.
After installation, add the Urlrewriter project to your own project
Modify the code according to the method in the address given above
Configure Web.config to start using.


What is HttpModule?

A simple understanding is a program that handles HTTP requests
For more detailed understanding, consult the SDK documentation.


How do I implement a pan-resolution?

First, add a *.kerry.com level two domain name to your server IP at the domain Name Service provider.
Then, set up a site in IIS, the main header of this site is left blank, the general port is 80. This site is the default Web site for the entire server port 80.
Add a wildcard application map to this site (the IIS site properties-> The home directory-> configuration), which is intended to asp.net ISAPI to take over any two-level domain name sites that are not explicitly in IIS.


Random input Level Two domain name, what happened?
When IIS detects that the incoming URL is a level two domain name, it will first check the IIS has not registered this two-level domain name site, if there is, go to this site, otherwise, will go to the default site, the default site is the previous configuration of the main header for the empty site. So, A port can have only one site with an empty host header.
We have set up the ASP.net ISAPI to take over the children without home. Write the program, parse the incoming URL, and perform the rewrite.
Current 1/2 page 12 Next read the full text
Related Article

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.