ASP.NET MVC gives developers full control over the structure of the URLs that are used to access their web applications. In ASP.NET Web Forms, the URL is mostly a reference to a physical file that lives on the web server. The ASP.NET runtime maps the server part of the URL to a server directory, and it uses everything that follows the server part to compose the actual path for the ASPX resource. We could say that, in Web Forms, the user asks for some content and receives whatever the system returns. In ASP.NET MVC, by contrast, the URL is more like a command that the user sends to the web server. In other words, ASP.NET MVC lets the user tell instead of just ask.
Technically speaking, you don't have to switch to ASP.NET MVC if the only change you seek is the ability to use personalized URLs. By writing a bunch of custom HTTP handlers and binding them to ad hoc URLs, you can achieve the same effect of using handcrafted URLs. On the other hand, this is just the mechanism that ASP.NET MVC leverages, and it's what makes ASP.NET MVC work on top of the same runtime environment as classic ASP.NET.
Routing is the technology that lets you gain total control over URLs. Routing is fully integrated both in ASP.NET MVC and ASP.NET 4. In Web Forms, the routing engine maps a recognized URL only to an ASPX page, whereas in MVC, the routing engine maps any recognized URL to a pair represented by a controller name and an action name. The routing related extensions that you find in ASP.NET MVC provide a good deal of control and programming power.
Routing in Action
To exercise control over incoming URLs, older versions of ASP.NET have a feature named URL rewriting. At its core, URL rewriting consists of hooking up a request, parsing the original URL, and instructing the HTTP runtime environment to serve a "possibly related but different" URL. ASP.NET MVC and newer versions of ASP.NET Web Forms rely on the URL-routing HTTP module for this service.
The URL-routing HTTP module intercepts any URL, parses the content, and dispatches the request to the most appropriate executor. Additionally, it denies the request if the URL doesn't match any predefined pattern.
Remember that in ASP.NET MVC, users make requests for actions on resources. However, the MVC framework doesn't mandate the syntax for describing resources and actions. The expression "acting on resources" might make you think of Representational State Transfer (REST). ASP.NET MVC is loosely REST-oriented in that it does acknowledge concepts such as resource and action, but it leaves you free to use your own syntax to express and implement resources and actions.
Your personalized URL syntax is expressed through a collection of URL patterns, also known as routes. A route is a string that represents the URL string without including protocol, server, or port information. A route may be a constant string, but it will more likely contain a few placeholders. Here's an example of a route:
/home/about This route is a constant string, and it's matched only by URLs whose absolute path is /home/about. Most of the time, though, you deal with parametric routes that incorporate one or more placeholders. A parameter is identified by a string enclosed in curly brackets, as follows:
/{resource}/{action}
/Customer/{action} Both routes are matched by any URLs that contain exactly two segments in addition to server information. The second segment requires that the first segment also equals the Customer string. By contrast, the first segment doesn't pose specific constraints on the content of the segments. The name of the placeholder ({action} in this example) is the key that your code uses to programmatically retrieve the content of the corresponding segment from the actual URL. Here's the default route for an ASP.NET MVC application:
{controller}/{action}/{id} The route contains three placeholders separated by the slash (/) delimiter. The following URL matches this default route:
/Customers/Edit/ALFKI You can add routes that have as many placeholders as is appropriate, and you can add as many of these routes as you want. You can even remove the default route from an ASP.NET MVC application.