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.

ROUTING

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

http://localhost:1585/Home/About

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:

routes.MapRoute(
    "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. FIGURE 8B-2

Note

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

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.