Asp. Net 4.0 SEO enhanced UrlRouting

Source: Internet
Author: User

Before. Net 4.0, in order to make search engine-friendly and user-friendly URLs, We need to rewrite the URLs by ourselves. Now we don't need it. Net 4.0 is doing this for us. UrlRouting is called Routing because it not only implements Url rewriting, but also obtains the rewritten Url through parameters for use on the page.

1. Common Use of Url Routing
UrlRouting is widely used in Asp. Net Mvc projects and can be used in Mvc. Therefore, it is transplanted to webform. Let's take a look at the usage in webform first.
Assume a scenario: we need to create a daily blog article page. The url we want is:
/Archive/2010/05/10/default. aspx
This address will be mapped ~ /Posts. aspx File

To use UrlRouting, You need to register the UrlRouting rule to the RouteTable. the following code is used to register the Routing rule in the Global file:

01 public static void RegisterRoutes(RouteCollection routes) 02 { 03      routes.Ignore( "{resource}.axd/{*pathInfo}" ); 04   05      routes.MapPageRoute( "blogs" , // Name the UrlRouting rule 06          "archive/{year}/{month}/{date}/default.aspx" , // The desired friendly Url format 07          "~/blogs.aspx" , // Map to the aspx page path 08          false , // Check User Permissions 09          new RouteValueDictionary{ { "year" , DateTime.Now.Year }, 10              { "month" , DateTime.Now.Month }, 11              { "date" , DateTime.Now.Date} 12          }, // Default value of the Parameter 13          new RouteValueDictionary {  14              { "year" , @"(19|20)d{2}" }, 15              { "month" , @"d{1,2}" }, 16              { "date" , @"d{1,2}" } 17          } // Parameter rules. Here we limit the year, month, and day in the url to the data format we want. 18          ); 19   20 } 21   22
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.