Chapter 9

Routing

What's In This Chapter?

  • Understanding URLs
  • Introduction to Routing
  • A peek under the Routing hood
  • A look at advanced Routing
  • Routing extensibility and magic
  • Using Routing 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 at Routing as a standalone feature.

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.