Skip to Main Content
ASP.NET 4 24-Hour Trainer
book

ASP.NET 4 24-Hour Trainer

by Toi B. Wright
July 2010
Beginner content levelBeginner
552 pages
10h 14m
English
Wrox
Content preview from ASP.NET 4 24-Hour Trainer

Chapter 15. URL Routing Overview

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:

http://localhost/recipes/list.aspx?category=soup

With URL routing, the URL for the same page looks like this:

http://localhost/recipes/category/soup

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 Global.asax.cs file.

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 Route class:

  • URL

  • Defaults

  • Constraints

  • DataTokens

  • RouteHandler

The URL property designates the URL pattern that the route will use. For example, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

ASP.NET 4 24-Hour Trainer

ASP.NET 4 24-Hour Trainer

Toi B. Wright
ASP.NET 4 Unleashed

ASP.NET 4 Unleashed

Stephen Walther, Kevin Hoffman, Nate Dudek

Publisher Resources

ISBN: 9780470596913Purchase bookExamplesErrata