O'Reilly logo

Professional ASP.NET MVC 3 by K. Scott Allen, Brad Wilson, Phil Haack, Jon Galloway

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 above two items only describe 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.

Comparing Routing to URL Rewriting

To better understand Routing, many developers compare it to URL Rewriting. After all, both approaches are useful in creating a separation between the incoming URL and what ends up handling the request and both of these techniques can be used to create pretty URLs for Search Engine Optimization (SEO) purposes.

The key difference is that URL Rewriting is focused on mapping one URL to another URL. For example, URL Rewriting is often used for mapping old sets of URLs to a new set of URLs. Contrast that to routing which is focused on mapping a URL to a resource.

You might say that routing embodies a resource-centric view of URLs. In this case, the URL represents a resource (not necessarily a page) on the Web. With ASP.NET Routing, this resource is a piece of code that executes when the incoming request matches the route. The route determines how the request is dispatched based on the characteristics of the URL—it doesn't rewrite the URL.

Another key difference is that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required