The ASP.NET Routing engine was added in .NET Framework 3.5 SP1. Now
Microsoft have added better support for using the engine in ASP.NET
WebForms 4.0 by using expression builders enabling bi-directional
routing.
Below is a summary of the code showed in the video. They use the
typical example of how Product.aspx?category=jerseys can map to
Product/Jerseys. Using the ASP.NET Routing engine this mapping can be
added using the RouteTable in Application_Start:
RouteTable.Routes.Add("Product",
new Route("Product/{name}",
new PageRouteHandler("~/Product.aspx")));
<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 for getting a URL and the second for getting
a value. The $ sign is used to access expressions from an aspx page:
To get the value from the name attribute, users use the Route object instead of the Request object:
or using an expression builder:
By using ASP.NET Routing and the new bi-directional support users
can decouple URLs from a physical Web Form, allowing friendlier URLs
and have search engines discover and use these.
版權
作者:靈動生活 郝憲玮
如果你認為此文章有用,請點選底端的【推薦】讓其他人也了解此文章,

本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接配接,否則保留追究法律責任的權利。