Asp.net rewrite URLReWriter with url to implement any second-level domain name

Source: Internet
Author: User

Asp.net uses url rewriting (URLReWriter) to implement any second-level domain name

I haven't written any technical articles for a long time. If you can't understand them, read a few 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, the http://love.kerry.com then we changed this address to an address that fits the needs of the program 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

<

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.