Analysis on ASP. NET url rewriting

Source: Internet
Author: User

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. But before the discussion, you must 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 problem be overwritten by ASP. NET url?

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 in this way.
Step 2: first, the entered address is parsed and finally comes to a web server. To IIS for processing. In the ASP. NET world, IIS will send such a request to a web processor for processing. Finally, the web processor returns the processing result to the browser and displays it to the user.

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 needs to be understood is that ASP.. NET url rewriting is only an insider situation that web developers know. users do not know what is happening at all. 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.

The so-called ASP. NET url rewriting is in this step. Use. in terms of net, we need to register an httpmodule for the application to process specific URLs and register the httpmodule. config, processing the url. In the httpmodule program we provide, it is roughly equivalent to such a process.

 
 
  1. // Use our httpmodule program to capture the original url
  2. StringOriginalUrl= "Http://love.kerry.com ";
  3. // Process the original url and get the final required url. The value is http://kerry.com?Lover=Notus 
  4. StringFinalUrl=Rewrite(OriginalUrl );
  5. // Context re-sends the url internally to IIS for processing
  6. Context. RewritePath (FinalUrl );

Next, we will rewrite ASP. NET 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 ASP. NET url rewriting, and the process of using ASP. NET 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 the script during processing.

Some problems may occur during the implementation process, mostly because the above articles are not carefully generated. But to be honest, it is not easy to read long articles. Next I will record some important issues. The last two problems show how to rewrite the target url with specific code 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 ASP. NET 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 ASP. NET 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, you can use it directly to implement simple ASP.. NET url rewriting. Zyw only makes modifications to this project to get all the URLs for greater control. As we can see, the urlrewriter in msdn didn't care about the domain name at the beginning. I started to give this question to the article because it was recently used in my project, this article was written by the way when I wrote the document.

  1. Analysis of Theme functions in ASP. NET development skills
  2. ASP. NET Dynamic Compilation
  3. Analysis on ASP. NET supported by Apache
  4. Introduction to ASP. NET Server standard controls
  5. Analysis on SQL Server Database Backup Recovery in ASP. NET

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.