Header add

In this article we will learn about what is the difference between Asp.net page life cycle and Asp.net Mvc page life cycle. Please read all the .NET Core articles in this link.

ASP.NET Web Forms

ASP.NET Web Forms use Page controller pattern approach for rendering layout. In this approach, every page has its own controller, i.e., code-behind file that processes the request.

In order to achieve stateful behavior, view state is used. Purpose was to give developers the same experience of a typical WinForms application.

Asp.net page life cycle Simply remember SILVER U

s- Start

I-Initialization

L-Load

V- Validate

E- Event handling

R -Rendering

U -Unload



ASP.NET MVC

ASP.NET Page Life Cycle is totally different from webforms, there are no events like we have in web forms for example: pre render, oninit etc. whenever we request a URL the only thing happens is, an instance of a controller is crated and some action method is called of it which results in rendering the View as HTML as response in the browser.

Routing

In ASP.NET application each asp.net page implements the IHTTPHandler interface.

This interface has a ProcessRequest() method that gets called when you request the page. The ProcessRequest() method is responsible for processing the request and generating the response. So in ASP.NET application it is simple, you request for a page in the url like http://mysite1\default.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.


Url Routing Module intercepts the Request

Whenever you make a request against an ASP.NET MVC application, the request is intercepted by the UrlRoutingModule HTTP Module.

When the UrlRoutingModule intercepts a request, the first thing the module does is to wrap up the current HttpContext in an HttpContextWrapper object.

The HttpContextWrapper object derives from HTTPContextBase class.

MVC Handler Executes

MVCHandler also inherit from the IHTTPAsyncHandler. When MVC Handler executes it will call the BeginProcessRequest method of the httpAsyncHandler asynchronously.

You can followed the In depth diagram of MVC. This image is taken from internet

In depth diagram of MVC


Summary

So far we learnt about What is the difference between Asp.net page life cycle and Asp.net Mvc page life cycle? Please share your feedback of the article if it need such improvements.

Post a Comment

Previous Post Next Post