Support for Bidirectional routing in ASP. NET web forms 4.0

Source: Internet
Author: User

. NET Framework 3.5 SP1 already contains the ASP. NET routing engine. Now Microsoft has added better support for the routing engine in ASP. NET webforms 4.0, which uses the expression constructor for Bidirectional routing.

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 section of the video.Code. 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 using ASP. NET 4.0, 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.

View Original English text:Bi-directional Routing Support in ASP. NET web forms 4.0

From: http://www.infoq.com/cn/news/2009/03/ASPNET40-Routing;jsessionid=A214E5CF80E29633AE06BCA857E893EB

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.