URL routing gives your application the ability to handle request URLs that do not map directly to specific files. Routing can be used to define URLs that are more meaningful to users and to improve the Search Engine Optimization (SEO) for your application. In this lesson I provide an overview of routing in ASP.NET 4. I cover the details for using routing in Web Forms and MVC in Lessons 15A and 15B, respectively.
Without URL routing, the URL for a page that lists recipes by category looks like this:
With URL routing, the URL for the same page looks like this:
This new URL is both easier for people to use and for search engines to index. Also, this new URL does not expose the file structure of your web application to the users.
To enable routing in your application, your application must have at least one route registered in the global
RouteTable. The global
RouteTable is defined in the
Global.asax file and is initialized during the
Application_Start method in the
Each route is a member of the
Route class. The
Route class is used to specify how routing is processed in your web application. You need to create a
Route object for each unique URL pattern that your application needs to handle. These are the properties of the
URL property designates the URL pattern that the route will use. For example, ...