Databases Reference
In-Depth Information
runtime. In particular, notice the Routes collection is used to generate a dynamic URL and
not a single particular route object. This is significant because the Routes collection evalu-
ates routes one by one, in the order they were registered, looking for the route matching
the supplied set of parameter values. As soon as the match is found, the further evaluation
is stopped, and the matching route is used to generate the URL.
A similar evaluation process occurs when the ASP.NET runtime needs to find a page
template to handle an incoming web request. It starts with the route that was registered
first and goes down the list until it finds the first match. All other routes that were regis-
tered after the first match are ignored.
Keeping in mind how the route evaluation process works, register the most specific routes
first, leaving the more generic routes until the end. For example, if you had registered the
following two routes in this order, your web application would always ignore the second
route when generating dynamic hyperlinks:
RouteTable.Routes.Add(new DynamicDataRoute( “{table}/{action}.aspx” ));
RouteTable.Routes.Add(new DynamicDataRoute(“{table}”)
{
Action = PageAction.List
});
In other words, a Product list hyperlink would always be presented to users as http://
localhost/Products/List.aspx and never as http://localhost/Products . However,
when handling incoming requests, the second URL would not match the first route, “fall
through,” and still get picked up by the second route.
Changing the order of route registrations gives you a fair amount of control over the URL
resolution process. However, when it is insufficient, you can use route constraints to make
it more specific. Route constraints are defined in the Constraints dictionary of a route
object as pairs of two string values, where first is a parameter name, and second is a
regular expression pattern that the parameter value must match. The following example
defines a route where the table parameter value can be either Products or Orders :
RouteTable.Routes.Add(new DynamicDataRoute(“{table}”)
{
Action = PageAction.List,
Constraints = new RouteValueDictionary(){{“table”,“Products | Orders”}}
});
RouteTable.Routes.Add(new DynamicDataRoute( “{table}/{action}.aspx” ));
Based on the route definitions in this last example, only the Products and Orders tables
will have the List URLs generated as http://localhost/Products or
http://localhost/Orders . All other tables will use the second route and have URLs
similar to http://localhost/Suppliers/List.aspx .
 
Search WWH ::




Custom Search