Support for Bidirectional Routing in ASP. NET Web Forms 4.0

Source: Internet
Author: User

Channel 9 has just released a new video of 10-4, showing how to use this new function in ASP. NET 4.0.

The following is a piece of code displayed in the video. They used a classic example to show how to set Product. aspx? Category = Jerseys ing to Product/Jerseys. When using the ASP. NET Routing engine, we can add this ing to RouteTable in Application_Start:

RouteTable.Routes.Add("Product",    new Route("Product/{name}",     new PageRouteHandler("~/Product.aspx")));

Currently, to obtain bidirectional Routing Support, you must rewrite the URL of the Query String. However, when ASP. NET 4.0 is used, you can register the following expression builder ):

<system.web>  <compilation>    <expressionBuilders ...>      <add expressionPrefix="RouteUrl"            type="System.Web.Compilation.RouteUrlExpressionBuilder" />      <add expressionPrefix="RouteValue"           type="System.Web.Compilation.RouteValueExpressionBuilder" />    </expressionBuilders>  </compilation></system.web>

The first expression is used to generate a URL, and the second is used to obtain the Route value. On the aspx page, you can use the $ symbol to access the expression:

<asp:HyperLink NavigationUrl="<%$ RouteUrl:RouteName=Product, name=Jerseys"      Text="Jerseys"      runat="server" />

To obtain the value in the name attribute, you can use the Route object instead of the Request object:

RouteData.Values["name"];

Or use the expression constructor:

<%$ RouteValue:name %>

Users can use the ASP. NET Routing engine and the new two-way support to decouple URLs from physical Web forms to support more friendly URLs for search engines.

  1. Details about. NET 4.0 code contract Components
  2. How to use MySQL database in. NET
  3. Analysis on Automatic Memory Management under the. NET Framework

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.