GeekArticles
Database
SQL Server
Database
SQL ServerURL Routing in ASP.NET 4.0
<p>
In the .NET Framework 3.5 SP1, Microsoft introduced ASP.NET Routing, which decouples the URL of a resource from the physical file on the web server.
With ASP.NET Routing you, the developer, define routing rules map route patterns to a class that generates the content. For example, you might indicate that the
URL <code>Categories/<i>CategoryName</i></code> maps to a class that takes the <i>CategoryName</i> and generates HTML that lists that products in a grid.
With such a mapping, users could view products for the Beverages category by visiting .NET 3.5 SP1, ASP.NET Routing was primarily designed for <a MVC</a> applications, although as discussed in
<a ASP.NET Routing Without ASP.NET MVC</a> it is possible to implement ASP.NET Routing in a Web Forms application,
as well. However, implementing ASP.NET Routing in a Web Forms application involves a bit of seemingly excessive legwork. In a Web Forms scenario we typically want to map a routing
pattern to an actual ASP.NET page. To do so we need to create a route handler class that is invoked when the routing URL is requested and, in a sense, dispatches the request
to the appropriate ASP.NET page. For instance, to map a route to a physical file, such as mapping <code>Categories/<i>CategoryName</i></code> to
<code>ShowProductsByCategory.aspx</code> - requires three steps: (1) Define the mapping in <code>Global.asax</code>,
which maps a route pattern to a route handler class; (2) Create the route handler class, which is responsible for parsing the URL, storing any route parameters into some
location that is accessible to the target page (such as and returning an instance of the target page or Handler that handles the requested
route; and (3) writing code in the target page to grab the route parameters and use them in rendering its content. Given how much effort it took to just read the preceding
sentence (let alone write it) you can imagine that implementing ASP.NET Routing in a Web Forms application is not necessarily the most straightforward task.
</p><p>
The good news is that ASP.NET 4.0 has greatly simplified ASP.NET Routing for Web Form applications by adding a number of classes and helper methods that can be used to
encapsulate the aforementioned complexity. With ASP.NET 4.0 easier to define the routing rules and no need to create a custom route handling class. This article
details these enhancements. Read on to learn more!
<br /><a More ></a></p>
Sponsored Links
Related Topics
Subscribe via RSS
SQL Server
- Naming Database Objects: Part II
- Trace Messages Part V: Trace Cleanup
- Naming Database Objects: Part I
- Multiple-Child Aggregation
- Creating SQL Tables for an Integrating Application Using Dexterity
- SQL Server 2005 Beta 2 Transact-SQL Enhancements
- .NET Rocks! - Brian Larson on SQL Server Reporting Services
- Computing the Trimmed Mean in SQL
- SQL Server 2000 Gains on Oracle
- Separator First Formatting (SFF)
