. 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