If you want to develop a web application or website using Asp.Net Framework, you have 3 options:-
- Asp.Net Webforms.
- Asp.Net MVC and
- Asp.Net Core
In this article, I will not discuss ASP.NETCore. You can think of ASP.NETCore as an upgrade of ASP.NET MVC. An MVC application can only be hosted on a Windows platform, whereas you can host an application developed using ASP.NETCore on any platform, like Linux, etc. You will learn everything about ASP.NETCore in the ASP.NETCore section.
Now, we are left with 2 options, i.e,
i) ASP.NET WebForm and
ii)ASP.NET MVC
Frankly speaking, nowadays nobody uses ASP.NET WebForms to develop a brand new web application, but you should learn it, because many applications that were developed using ASP.NET WebForms still exist. You may face a situation where you have to work on those old projects, or the requirement can be to upgrade those projects into ASP.NET MVC or Core. So, you will be stuck if you don't know how the current application works.
Now the question arises, when we had ASP.NET WebForms, why did Microsoft come up with new ASP.NET MVC?
ASP.NET WebForms was famous for almost a decade among developers because of its RAD environment. RAD stands for Rapid Application Development.
In Asp.Net Webforms we had:
- Server Controls and
- Code behind
That is, developers were able to drag and drop UI Controls, called Server Controls, to the designer area and corresponding HTML was automatically generated.
Also, each control was provided with events, methods, and properties, and the developer just had to set the properties and write code in the generated event in code behind. So the development used to be faster.
In short, from the developer's point of view, they had to work less to achieve more. But, web developers make projects for clients or audiences and the audience has nothing to do with our time.
What a client needs is only a well-performing application and the performance of any application is decided by how fast the output or the result is being served, meaning how fast the server is processing a request and sending the response back to the client machine or browser.
But the performance of an ASP.NET WebForms application was not as good as it should be. The root cause was itself the RAD environment.
Each time the server controls needed to be converted into HTML, called Rendering. Also, with each control, the ViewState was enabled by default to maintain the state. This ViewState used to generate a huge amount of bytes, which increases the page load and makes it slower.
The other disadvantages of using Asp.Net Webforms are :-
- Its Page-First architecture, meaning the request always comes to the page and unnecessarily goes to the complicated page life cycle even when it is not needed. Meaning, the physical presence of the page is necessary.
- The aspx page (Design) and aspx.cs (code/code-behind) are dependent on each other, meaning they are tightly coupled, because of which the same view cannot be used with different code and different code cannot be used with another view.
- The code-behind page, i.e, the aspx.cs page is inherited from System.Web.UI.Page, which makes it a special page, and unlike a normal class, its object cannot be created.
So, no reusability of code is there.
The code written in the button click event under one page can not be reused in other pages by creating an object of the desired event containing the page. - Sending a response other than HTML is hectic, and HTML is the only preferred response type.
Due to all of the above reasons, Microsoft launched ASP.NET MVC with:
- No Server Controls, meaning no extra time for HTML conversion.
- No code-behind, meaning better reusability of code.
ASP.NET MVC is nothing but a technology that follows the MVC architectural pattern, which gives the best separation of components. Where your aspx page becomes a view and code behind becomes a controller, which is a simple class that gives the flexibility of Unit Testing and Reusability.