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://www.bianceng.cn, 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://www.bianceng.cn 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://www.bianceng.cn";
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.