Chapter 9

Routing

— By Phil Haack

What's In This Chapter?

  • All about URLs
  • Routings 101
  • A peek under the Routing hood
  • A look at advanced Routing
  • Routing extensibility and magic
  • How to use Routings with Web Forms

When it comes to source code, software developers are notorious for fixating on little details to the point of obsessive compulsion. We'll fight fierce battles over code indentation styles and the placement of curly braces. In person, such arguments threaten to degenerate into all-out slap fights.

So it comes as a bit of a surprise when you approach a majority of sites built using ASP.NET and encounter a URL that looks like this:

http://example.com/albums/list.aspx?catid=17313&genreid=33723&page=3

For all the attention we pay to code, why not pay the same amount of attention to the URL? It may not seem important, but the URL is a legitimate and widely used user interface for the Web.

This chapter will help you map logical URLs to action methods on controllers. It also covers the ASP.NET Routing feature, which is a separate API that the ASP.NET MVC framework makes heavy use of in order to map URLs to method calls. The chapter first covers how MVC uses Routing and then takes a peek under the hood a bit at Routing as a standalone feature.

Get Professional ASP.NET MVC 3 now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.