Introduction to Routing

Routing within the ASP.NET MVC framework serves two main purposes:

  • It matches incoming requests that would not otherwise match a file on the file system and maps the requests to a controller action.
  • It constructs outgoing URLs that correspond to controller actions.

The preceding two items describe only what Routing does in the context of an ASP.NET MVC application. Later in this chapter we'll dig deeper and uncover additional Routing features available for ASP.NET.

One constant area of confusion about Routing is its relationship to ASP.NET MVC. In its pre-beta days, Routing was an integrated feature of ASP.NET MVC. However, the team saw that it would have a useful future as a fundamental feature of ASP.NET that even Web Pages could build on, so it was extracted into its own assembly and made part of the core ASP.NET framework. The proper name for the feature is ASP.NET Routing, but everyone simply shortens it to Routing.
Putting this feature into ASP.NET meant that it became a part of the .NET Framework (and, by association, Windows). So, while new versions of ASP.NET MVC ship often, Routing is constrained by the schedule of the larger .NET Framework; hence, it hasn't changed much over the years.
ASP.NET Web API is hostable outside of ASP.NET, which means it can't use ASP.NET Routing directly. Instead, it introduces a clone of the Routing code. But when ASP.NET Web API is hosted on ASP.NET, it mirrors all the Web API routes into the core ASP.NET ...

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.