Introduction
MVC Application Page Life Cycle
In asp.net application it is simple, you request for a page in the url like http://DemoWeb\Home.aspx and then it search for that page on the disk and execute the ProcessRequest method and generate the response.
However in MVC application it doesn’t work in that way. There is no physical page exist for a particular request. All the requests are routed to a special class called Controller. The controller is responsible for generating the response and sending the content back to the browser.
In MVC whenever you build your Application than your one Controller can handles lots of Requests. Here is the Steps inlcluded in MVC page Life Cycle-
Asp.net Routing is the first step in MVC request cycle. 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 is not found in the Route Table.
MVC requests are mapped to route tables which in turn specify which controller and action to be invoked. So if the request is the first request the first thing is to fill the route table with routes collection. This filling of route table happens in the global.asax file.
Depending on the URL sent "UrlRoutingModule" searches the route table to create "RouteData" object which has the details of which controller and action to invoke.
The "RouteData" object is used to create the "RequestContext" object.
This request object is sent to "MvcHandler" instance to create the controller class instance. Once the controller class object is created it calls the "Execute" method of the controller class.
The Execute() method gets the Action from the RouteData based on the URL.The Controller Class then call the ContollerActionInvoker that builds a list of parameters from the request.
These parameters, extracted from the request parameters, will act as method parameters.The parameters will be passed to whatever controller method gets executed.
Finally It will call the InvokeAction method to execute the Action.
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.
In this article we will learn about the Life Cycle of a MVC Application. How MVC request handle and how MVC URL request different from ASP request.
MVC Application Page Life Cycle
In asp.net application it is simple, you request for a page in the url like http://DemoWeb\Home.aspx and then it search for that page on the disk and execute the ProcessRequest method and generate the response.
However in MVC application it doesn’t work in that way. There is no physical page exist for a particular request. All the requests are routed to a special class called Controller. The controller is responsible for generating the response and sending the content back to the browser.
In MVC whenever you build your Application than your one Controller can handles lots of Requests. Here is the Steps inlcluded in MVC page Life Cycle-
Asp.net Routing is the first step in MVC request cycle. 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 is not found in the Route Table.
MVC requests are mapped to route tables which in turn specify which controller and action to be invoked. So if the request is the first request the first thing is to fill the route table with routes collection. This filling of route table happens in the global.asax file.
Depending on the URL sent "UrlRoutingModule" searches the route table to create "RouteData" object which has the details of which controller and action to invoke.
The "RouteData" object is used to create the "RequestContext" object.
This request object is sent to "MvcHandler" instance to create the controller class instance. Once the controller class object is created it calls the "Execute" method of the controller class.
The Execute() method gets the Action from the RouteData based on the URL.The Controller Class then call the ContollerActionInvoker that builds a list of parameters from the request.
These parameters, extracted from the request parameters, will act as method parameters.The parameters will be passed to whatever controller method gets executed.
Finally It will call the InvokeAction method to execute the Action.
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 comments:
Post a Comment