In a regular ASP.NET web application, each URL is mapped to a file on a disk. For example, a request for http://www.example.com/Products/Show.aspx?id=5 really maps to a file called Show.aspx
on the web server's disk.
Using ASP.NET routing, you define specific patterns for a URL that map to a certain handler class that will take care of the request. For example, a URL in the form of http://www.example.com/Products/Show/5 could be matched with a pattern http://www.example.com/{controller}/{action}/{id}. The variables between {
and }
are populated with the actual values from the request URL, and will map to the HomeController
and to the Index
action if no other value can be deduced from the URL.
These URL patterns can also be used to programmatically create URLs that correspond to them. All hyperlinks in your ASP.NET MVC application can be generated this way and can thus easily be managed by maintaining the route table.