Chapter 8B. The Request Life Cycle in MVC

Every time a page is requested using the ASP.NET MVC framework, it must complete a request life cycle. In this lesson I describe the steps in a page's request life cycle.


This is a sample URL that is used to request a page using the ASP.NET MVC framework (see Figure 8B-1):



Figure 8B.1. FIGURE 8B-1

Notice that the URL does not refer to a specific page. Instead, the ASP.NET MVC framework uses a routing table to determine how the request should be handled. When you create an MVC application, routing is automatically enabled in the Global.asax.cs file.

This is the routing information included in the Global.asax.cs file that is used by the sample MVC application that you created in the previous lesson:

    "Default",                                              // Route name
    "{controller}/{action}/{id}",                           // URL with parameters
    new { controller = "Home", action = "Index", id = "" }  // Defaults

The route is used to determine which controller and action should be used to process the request. When the "Default" route is applied to the following request the route dictates that the HomeController should be used with the About action. See Figure 8B-2.


Figure 8B.2. FIGURE 8B-2


The word Controller is automatically added to the name of the controller. ...

Get ASP.NET 4 24-Hour Trainer now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.