Introduction
In this post, we are going to discuss about the each step in the life of an ASP.NET MVC from request to response. Here we will walk through the steps involved in a life of ASP.NET MVC request.There are mainly five main steps that happen when you make a request from an ASP.NET MVC website.
Flow Of MVC Request :
Step 1 – Request
Receive first request for the application. In the Global.asax file, route objects are added to the Route table object.ย
1 2 3 4 5 6 7 8 9 |
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); } |
Step 2 โ The Routeย
The entry point for every MVC Application begins with Routing. After the application receives the request from the user, it uses URL Routing Module to handle the request. The RouteTable maps URLs to handlers.ย ย Basically routing is a pattern matching system that matches the requestโs URL against the URL patterns which is present in the Route Table. The Routing engine redirectย the request to the corresponding IRouteHandler when the match found in the pattern. If corresponding requested URL not found in route tableย then it will returnย a 404 HTTP status code.
Step 3ย โ The MvcHandler Executes
It is the responsibility of the RouteHandler to determine the HTTP handler that will serve the request, by looking at the received RequestContext.ย The RouteHandlerย object creates an instance of the MvcHandler class and passes the RequestContext instance to the handler.
RequestContext instance is used to identify the IControllerFactory object to create the controller instance.
The MvcHandler method calls the controller’s Execute method.
Step 4ย โ The Controller Executes
The controller determines which actionย method to execute.ย MvcHandler uses IControllerFactory instance and to get IController object.ย Mvc controllers implement IController interface to execute the method which actually execute your action method.
Step 5 โ Action Invoked
After controller gets instantiated ActionInvoker will determines which Action method need to execute. ActionNameSelectorAttribute and ActionMethodSelectorAttribute methods used to select action method. The action method receives user input then executes the result and returning a result type to view.ย
The result type can be ViewResult, RedirectToRouteResult, RedirectResult, ContentResult, JsonResult, FileResult, and EmptyResult. At last the view has been render to the browser as response.
Keep Cool Coding…
superb explainations this topic
thanks
Thanks Priya Kale
Very helpful and Great information,
I appreciate advise especially coming from a professional.
Thanks again and keep up the great work!
Very well explained. Covered almost every topic of basics. Its a great help to me. Thanks for sharing :)
This is the best explanation for Lifecycle of an ASP.NET MVC. Thank you again!!