Sep 25, 2015

MVC Life Cycle

diagram you will come to know How MVC application behaves when it’s invoked from the browser. So, as you see in the diagram, as soon as request comes from the browser, it is picked up by the routing engine. Hence, ASP.NET Routing is the first step in MVC Life cycle. Basically it is a pattern matching system which matches the request’s pattern against the registered 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. If the routing engine doesn’t match the pattern then it returns 404 HTTP Status code.


Then, MVC handler implements IHttpHandler interface and further process the request by using ProcessRequest method. Then in third step MVCHandler uses the IControllerFactory instance and tries to get a IController instance. If successful, then Execute method is called. Now, once the controller has been instantiated, Controller's ActionInvoker checks which action to invoke on
the controller. Next, 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. Now, the next step is the execution of the View Result which involves the
selection of the appropriate View Engine to render the View Result. It is basically handled by IViewEngine interface of the view engine. Now, at last Action method returns a string, 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.














No comments:

Post a Comment