Life cycle of MVC request is a series of steps involved in processing client request. There are seven main steps that happen when you make a request to Asp.net MVC web applications.

Routing:

The ASP.NET Routing module is responsible for mapping incoming browser requests to particular MVC controller actions. Basically it is a pattern matching system that matches the request’s URL against the registered URL patterns in the Route Table. When a matching pattern found in the Route Table, the Routing engine forwards the request to the corresponding IRouteHandler for that request. The default one calls the MvcHandler. The routing engine returns a 404 HTTP status code against that request if the patterns are not found in the Route Table.

MvcHandler:

MvcHandler handler is responsible for initiating the ASP.NET pipeline for an MVC application. MVC handler implements IHttpHandler interface and further process the request by using ProcessRequest method as shown below

MvcController:

The Controllers contains the controller classes responsible for handling user input and responses. MVC requires the name of all controllers to end with "Controller". The ASP.NET MVC framework maps URLs to classes that are referred to as controllers. Controllers process incoming requests, handle user input and interactions, and execute appropriate application logic. A controller class typically calls a separate view component to generate the HTML markup for the request.

* Locating the appropriate action method to call and validating that it can be called.

* Getting the values to use as the action method's arguments.

* Handling all errors that might occur during the execution of the action method.

* Providing the default WebFormViewEngine class for rendering ASP.NET page types (views).

All controller classes must be named by using the "Controller" suffix. The following example shows the sample controller class, which is named HomeController. This controller class contains action methods that render view pages.

Action Execution:

Once the controller has been instantiated, Controller's ActionInvoker determines which specific action to invoke on the controller. Action to be execute is chosen based on attributes ActionNameSelectorAttribute (by default method which have the same name as the action is chosen) and ActionMethodSelectorAttribute(If more than one method found, the correct one is chosen with the help of this attribute).

View Result:

The action method receives user input, prepares the appropriate response data, and then executes the result by returning a result type. The result type can be ViewResult, RedirectToRouteResult, RedirectResult, ContentResult, JsonResult, FileResult, and EmptyResult.

The ViewResult class implements the abstract ViewResultBase class and is used to render a view. This class contains methods for finding the view to render and for executing the result. This class also contains properties that identify the view to render, the name of the view, the name of the master view, view data, temporary data, and a collection for view engines for the application.

View Engine:

In MVC, View engine is the one that works between your View and browser to provide valid HTML output to your browser by compiling the code inside your View. There are many view engines available and some of them are ASPX, Razor, Spark etc.

View:

Action method may returns a text string,a binary file or a Json formatted data. The most important Action Result is the ViewResult, which renders and returns an HTML page to the browser by using the current view engine.

0 Comments1

Sorry, No more post.

Your Comment

Login To Comment

discard

By posting your Comment, you agree to the privacy policy and terms of service.