Web Form And MVC Life Cycle

When we open the HTML file into the browser, it can open into the browser. But when we try to open the file in PHP or asp into the browser it can’t open into the browser because these languages are not native to the browser. Only client-side ‘html’ language is native to the browser. And if we want to open the PHP or asp file into the browser then we need a server who translates this code into browser native code.

And there are some important protocols who play a role in client-server communication. We need to follow these standards. So we follow the HTTP protocol to communicate over the web.

Why is this standard important for communication?

Actually, we have many technologies like PHP, asp.net, Android, IOS. So if we want to communicate over the web then we need to follow HTTP protocol, and it makes the communication easy for all of the technologies. Every technology on the web follows a specific standard, otherwise, it can’t work over the web.

ASP.NET

 

We can see in the above picture HTTP Request and HTTP Response.

Remember:

These requests are synchronous as the arrow sign is in one side direction, it means one-way communication at a time. These requests are not asynchronous.

Synchronous         (1 task at a time)

Asynchronous       (Multiple tasks at a time)

Now the question is how multiple things are happening at the same time in the web application like Facebook etc. If we make the request asynchronous, then we can request multiple things through ajax and it is done by XML HTTP request. It means we are sending multiple calls on the same protocol and multiple responses come back on the same protocol response. Web 2.0 introduces Ajax.

Web Form Life Cycle

Let’s discuss the life cycle of Web forms. The HTTP request goes to the web server, now server translates our (.aspx) web form page. And as we already know that CLR plays its role under the hood to compile any language. CLR interacts with the database if there is any need to show the data on web form page and then it converts back into HTML and shows on the browser.

ASP.Net Web Forms is actually event-driven model which means we hit any event on the screen and some actions manipulate against this event trigger.

Life Cycle

 

This is the web form (1 page) life cycle. It means when we hit the 1 action in web form, then all these blue, green, brown actions execute then our action is performed. OMG! How costly is this?

And now let’s suppose we are using some master page which includes page header, footer, some user control for any specific section then what will happen under the hood in a server? How many actions will the server execute? And if our application is enterprise, then our server will surely go down, it can't respond anymore to any request. For example, the result will be announced at a specific date and at a specific time. Now every person will try to reach the web and want to know the results but if a lot of actions execute on each request then our web server will surely crash.

MVC Life Cycle

MVC Life Cycle

 

MVC is totally action based, our request comes to the controller and then the action executes if it needs data. Then it can retrieve the data from the model and then show the views. Everything is perfect. And these views go back to the client computer as a response and show on the browser. Now, this response can be HTML if the request comes from the browser, it can be in JSON or XML format if a request comes from any device using web service etc. Don’t be confused about response and view in this picture. The view is all about showing data on the browser.


Similar Articles