By default when you use Visual Studio to create a new
project using the "ASP.NET MVC Web Application" template it adds an
ASP.NET Application class to the project. This is implemented within the
Global.asax code-behind:
Figure 2
The ASP.NET Application class enables
developers to handle application startup/shutdown and global error handling
logic.
The default ASP.NET MVC Project Template
automatically adds an Application_Start method to the class and registers two
URL Routing rules with it:
Figure 3
The first routing rule above indicates that the ASP.NET MVC
framework should by default map URLs to Controllers using a
"[controller]/[action]/[id]" format when determining which Controller
class to instantiate, and which Action method to invoke (along with which parameters
should be passed in).
This default routing rule is why a URL request for
/Products/Detail/3 in our e-commerce browsing sample from Part 1 automatically invokes the Detail method on our
ProductsController class and passes in 3 as the id method argument value:
Figure 4
The second routing rule above is added to special-case the
root "Default.aspx" URL in our application (which is sometimes passed
by web servers in place of "/" when handling requests for the root
URL of an application). This rule ensures that requests for either the
root "/Default.aspx" or "/" to our application are handled
by the "Index()" action on the "HomeController" class
(which is a controller automatically added by Visual Studio when we created a
new application using the "ASP.NET MVC Web Application" project
template).