asp.net use URL rewrite (urlrewriter) to implement any level two domain name
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 address with no parameters, http://love.kerry.com and then we change this address to a program-required address with parameters, http://kerry.com? Lover=notus, and finally deal with it.
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