This entry is part 3 of 4 in the series ASP.NET - WebForms versus MVC

Web Forms Web Application Advantages

The old ASP.NET Web Forms framework is a mature framework that is being used in a lot of applications and web sites. The advantages of Web

Forms are:

  1. State Management – in Web Forms state management is more easier. The use of ViewState or server based forms simplify the state management

    but reduce the control over the application behavior.

  2. Event driven model – the Web Forms uses an event model that helps to develop a more event driven application. You can wire to a lot of

    events that are supported by the framework through controls and your pages.

  3. Server Controls – the Web Forms approach has a massive control libraries that can be used to build your application. On the other hand, the MVC framework doesn’t currently have a lot of controls that can help to build a more rich application and therefore you’ll have to build them yourself.
  4. Rapid development – it is faster to develop applications in the Web Forms approach. The reasons for that are the support for components like server controls or the page class that make it easier to develop (but brings a lot of cons which are some of the advantages of MVC framework).

Web Forms Disadvantages

  1. Web Forms have some severe set backs, most notably is that we are limited to a single Form tag on a page which requires the entire contents of the page to be posted back and processed by the server, even if the only change is the selection of an item in a drop down menu (where the drop down menu needs to auto-postback to allow us to perform some other kind of logic). This is a HUGE disadvantage as the developer can not process parts of the page in the same manner we would have using normal HTML elements and multiple form tags which enable partial-page processing. 
  2. Another major disadvantage is VIEWSTATE, Microsoft’s answer to page state management. Viewstate stores just that, the state of elements on the page, so that the developer no longer has to specifically handle this on a postback. However VIEWSTATE bloats the page, often enormously, and becomes a major problem when a page contains lots of controls and data, causing huge performance lags as all this data must be passed back and forth to the server on each postback which is only further impacted by the "single form tag" problem.

MVC Advantages (over asp.net webforms)

1. Testability : The ASP.NET MVC framework does not use the ASP.NET postback model for interactions with the server. Instead, all end-user interactions are routed to a controller class. This maintains separation between UI logic and business logic and facilitates testability. As a result, the ASP.NET view state and ASP.NET page life-cycle events are not integrated with MVC-based views.

2. No Postbacks, No ViewState, No 1-1 Mapping between URL and Physical File. Rather than the traditional ASP.NET Web Forms under which the controller and view are within a page (the .aspx corresponds to the View and .aspx.cs to Controller), by introducing a new REST model, each page in ASP.NET MVC is split into two distinct components — Controller and View — that operate over the same Model data.

Also, the MVC framework doesn’t consider any URL as the endpoint to a physical server file to parse and compile to a class. In ASP.NET Web Forms, we have a 1:1 correspondence between a URL and a resource. The only exception to this rule is when you use completely custom HTTP handlers bound to a particular path.

In the MVC framework, a URL is seen as the means to address a logical server resource, but not necessarily an ASPX file to parse.  In the end, the MVC framework employs a centralized HTTP handler that recognizes an application-specific syntax for links. In addition, each addressable resource exposes a well-known set of operations and a uniform interface for executing operations.

In the MVC world, we do not have to worry about the ViewState or Postback any longer. This also leads to ‘No Client Ids Pollution’. The client side HTML contents are cleaner since there are no “client side IDs”.

3.  No databinding – which leads to complete control over the HTML. Instead, the data is placed in a model class and retrieved using a strongly typed view that has direct access to that model.

4. Extensible – the MVC framework components were designed to be pluggable and extensible and therefore can be replaced or customized easier then Web Forms.

5. ASP.NET features are supportedMVC framework is built on top of ASP.NET and therefore can use most of the features that ASP.NET include such as the provider architecture, authentication and authorization plumbing, membership and roles, caching, session management and more.

6. URL routing mechanism – the MVC framework supports a powerful URL routing mechanism that helps to build more searchable URLs in your application, assisting in search engine optimization.

MVC Disadvantages

  1. User controls (and server controls) are much harder to use in MVC world.
  2. DataBinding on controls is much harder
  3. Need to download and install ASP.NET MVC (installs some dlls in the gac)
  4. Any public method in a controller is exposed as a controller action. You need to be careful about this. This means that any public method contained in a controller can be invoked by anyone with access to the Internet by entering the right URL into a browser. e.g. wwwxyz.com/shop/delete/12  will delete shop with ID 12.

When To Use ASP.Net MVC

Unit Testing

This is possibly the most significant reason to consider using ASP.NET MVC.  Whereas web forms have been notoriously difficult to test (due to the page event lifecycle), the MVC framework lends itself to unit testing.  

Control and Extensibility over the HTML

ASP.NET MVC gives you more control and extensibility options than ASP.NET web forms.  You get complete control over the page request lifecycle and the ability to substitute out several key pieces of the framework (e.g. view engine, routing, etc.), none of which is possible with ASP.NET web forms.

In addition to this, you also gain full control over the rendered HTML.  In WebForms, the generated HTML is usually not a candidate for light reading. It is ugly – cluttered – and overly prosaic. Web controls generate ids and hidden fields that are difficult to apply CSS styling (or javascript code) to.   MVC, on the other hand, forces you to generate cleaner HTML.  There aren’t any datagrids, repeaters, listboxes etc. that generate markup for you. It’s just the HTML along with a few extension methods.

When not to use ASP.Net MVC

  • If your application relies heavily on 3rd party controls

There are lots of 3rd party controls and extensions for WebForms in the marketplace (see my post on using Syncfusion Grid Control for grid display on steroids).  There is so much out there that you can do quite a bit without a whole lot of code.

  • If you do not want to build on top of the MVC Framework

ASP.NET MVC has very few features.  It has some basic url helpers, html helpers, and ajax helpers.   There is very little ‘out of the box’.

Anuj holds professional certifications in Google Cloud, AWS as well as certifications in Docker and App Performance Tools such as New Relic. He specializes in Cloud Security, Data Encryption and Container Technologies.

Initial Consultation

Anuj Varma – who has written posts on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.


Series NavigationBuilding Rapid, Testable Web-Forms–Hello World with ASP.NET MVCBuilding Rapid, Testable Web-Forms– Conclusion