IIS URLs rewriting and asp.net routing (bottom)

Source: Internet
Author: User

In the IIS URLs rewriting and ASP.net routing (above), we analyze and contrast the concepts and functions of the IIS URL rewriting and ASP.net routing, and after we have understood these fundamentals and similarities and differences, how do we Select the appropriate URL optimization program in the application? In this paper, we will discuss the analysis of this, and give examples of several cases of synergistic application.

How do we choose?

First, if our web application has any dynamic Web-page technology other than ASP.net, then the choice is absolutely obvious: rewrite the module with the IIS URL (IIS Url-rewrite module). Otherwise, the main rules of judgment are as follows:

1. Use asp.net routing if our asp.net Web application uses asp.net MVC or asp.net Dynamic Data technology. Our application URL optimization process will benefit from native support (asp.net MVC and asp.net Dynamic data directly include ASP.net Routing). Early ASP.net routing does not support WebForm, and the current version already supports standard WEB form applications. See here for details.

2. If we are based on an existing ASP.net website and wish to try not to change it, use the URL rewrite module. Because the URL rewrite module can provide a "user-friendly" search engine friendly URL to a Web site without changing existing programs. Again, it allows us to create redirect rules to redirect search engine crawlers to new URLs.

In practice, however, these two technologies are not just one, they can often complement each other. In the following sections, we will outline several cases of collaborative use of asp.net Routing and URL rewrite modules.

Enforce a standard URL for a Web site

For example, we want to force the use of http://www.mysite.com/home/about to replace Http://mysite.com/Home/About. When the client requests a URL that does not conform to the standard format, the client trophy jumps to a URL that conforms to the standard format. In this case, we can use the URL rewrite module to force the URL to jump, and use the ASP.net route to select a handler to process the requested URL path.

The following code shows the URL rewrite module configuration code that might be used in this case:

<rewrite>
     <rules>
         <rule name="Enforce canonical hostname"  stopProcessing="true">
             <match url="(.*)" />
             <conditions>
                 <add input="{HTTP_HOST}" negate="true"  pattern="^www\.mysite\.com$" />
             </conditions>
             <action type="Redirect" url="http://www.mysite.com/{R:1}"  redirectType="Permanent" />
         </rule>
     </rules>
</rewrite>

Provide static content from other Web sites or other servers

For example, our web site is deployed on multiple servers, and the content of dynamic pages is deployed on one server or one Web site, and all static content is deployed on another server or on another Web site. At this point, we can use the URL rewrite module to collaborate with the IIS application request Routing module to transfer requests for the lens content to a static content server (Web site), while the current server handles all dynamic page requests. In this environment, asp.net routing happens to be effective only for all dynamic Web content, not for static content.

The following code shows the URL rewrite module configuration code that might be used in this case:

<rewrite>
   <rules>
     <rule name="Forward to static file server">
       <match url="^.+\.(?:jpg|bmp|gif)$" />
       <action type="Rewrite" url="http://static_file_server/ {R:0}" />
     </rule>
   </rules>
</rewrite>

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.