The Web Forms vs MvC debate

Currently Microsoft ships two frameworks to develop web application with the .Net framework (Asp.Net Web Forms and Asp.Net MvC). Microsoft is developing and supporting both frameworks alongside each other, emphasizing that developers have to pick the right tool for the task at hand. Despite the position Microsoft takes on the subject, there has been debate within the .Net community as to which framework is the better framework for developing web applications. In this article I discuss my views on the subject, which I consider an important subject and thus a good starter posting for an Asp.Net blogger.

Why use frameworks?

Before we get into comparing the Web Forms framework to the MvC framework, I want to address the benefits of using application development frameworks in the first place. First and foremost a framework helps me be an efficient developer by taking care of the general overhead associated with developing web applications. This lets me focus on the client specific challenges. Secondly a framework can help me deliver high quality applications by supporting and encouraging the use of design patterns and best-practices.

At this point in time approximately 80% of all Asp.Net implementations use Web Forms. This is no surprise since Web Forms is been around considerably longer, and has been quite successful in the past. But the MvC framework seems to be on the rise and having worked with both frameworks, I can see why the MvC framework is gaining momentum. It does very well in a lot of the areas where the Web Forms framework has been having troubles.

The Asp.Net Web Forms framework

The Asp.Net Web Forms framework has been around for quite some time, but it’s still maintained and even extended by Microsoft, the last release being the .Net framework 4 release. Despite these efforts, as it stands now, using the Web Forms framework does not help me being an efficient developer. Although this might sound a bit harsh it should be said, the reason the Web Forms framework was created simply doesn’t serve the current needs of enterprise web applications developers.

The original reason for creating the Web Forms framework was to offer desktop developers a smooth transition to web development. This design goal brought forth technical difficulties because there are differences in state between the desktop and the web, which uses the inherently stateless HTTP protocol. To overcome these challenges Web Forms employs an event-driven postback/viewstate development model to hide developers from the stateless web. However, this development model is fragile and has been known to cause problems with scaling complexity.

Aside from the technical issues, the Web Forms framework suffers from a lack of control, mainly with the way it generates output. The Web Forms framework relies on controls to build applications. These controls generate output, giving the developer only very limited control over the output. This makes it more difficult to do front-end and client-side development. This also poses challenges when working with accessibility and html standards. While new options for control over the output were added with the .Net framework 4 release, it’s still limited.

The second point where the Web Forms framework is not successful is in help me deliver quality applications. In all honesty it has to be noted that being a good developer is still mostly the responsibility of the developer itself, and not just that of the framework. However a framework can inherently support best-practices and encourage developers to use best-practices. There is no such support when working with the Web Forms framework. Important best-practices like seperation of concerns, loose coupling and testability have to be implemented by the developers themselves. This shortcoming was remedied somewhat by the creation of the design pattern called MVP (Model View Presenter), but these efforts have nothing to do with the framework, and is not enforced by the framework in any way.

The Asp.Net MvC framework

The Asp.Net MvC framework was developed by Microsoft to be an alternative to Asp.Net Web Forms for building web applications. The framework utilizes the MVC (Model View Controller) design pattern, and is build using important object oriented principles and best-practices like separation of concerns, loose coupling and testability. I’m not going to explain these best-practices in this article, but there’s a wealth of documentation on what they are and how harness their power. The MvC framework also respects web standards, so there’s no bypass of the inherently stateless nature of the HTTP protocol.

The first point where the MvC framework is really successful l: helping me be an efficient developer. The reason the MvC framework succeeds where the Web Forms framework fails is by serving the current needs of enterprise web applications developers. It takes care of the common overhead like you would without compromising on flexibility. This is where it beats the Web Forms framework, the MvC framework gives developers total control over everything that is going on.

The second point where the MvC framework is successful l: helping me deliver quality applications. The framework inherently works with the MvC design pattern, giving separation of concerns out of the box. Separation of concerns makes it easier to manage complexity and make changes on certain isolated parts of the application. Loose coupling is incorporated into the MvC framework itself, enabling developers to swap even the core component of the frameworks with custom replacements to change the behavior of the framework without effecting other components. This makes amazing flexibility and makes working with the best-practice of loose coupling easy. Testability is also relatively easy with the MvC, this best-practice is emphasized by Microsoft since unit-testing is been getting a lot of attention lately.

Wrapping up

Responsibility for the overall quality of the application still lies with the developers. They have to use the best-practices and make sound decisions when developing, whatever framework they use. Working with the MvC won’t guarantee success, it just makes it easier to be successful. If you have had success with the Web Forms framework in the past or still, you can continue to do so. However I would advise that everyone doing Asp.Net development at least fiddle around with the MvC framework a little, it might just be the thing for you.