WebForms vs. MVC

by kelly 7. September 2009 12:33

I have now played around with ASP.NET MVC Framework 1.0 over the last few months in great detail. I first was introduced to this framework at DevTeachthrough a presentation from the gift to software developers, Justice Gray. A new web framework that was not control-based (and no ViewState) sounded good, as many of the projects I have worked on are not necessarily web applications but public-facing, information-providing web sites and some of the elements and controls in WebForms is a tad overkill and performance draining at times.

I recently read and commented on the book “Professional ASP.NET MVC 1.0” in my blog. In that post, I indicated that what I thought was missing from the book: reasons and justifications of when to use one over the other. The book was technical in nature (as it should be), but my experience is that developers want to use newer things and they need to be able to justify a newer technology to their boss instead of just “because it’s there”. So, what follows are my opinions on when to use WebForms and when to use ASP.NET MVC (I’ll just call it MVC for the purpose of this post – I won’t be referring to any other MVC frameworks at this time). These are just opinions and are based upon where I see the strengths of each of the systems.

WebForm Strengths

I think the main strength of the WebForm framework is its ability to run as an true application environment. It’s initial design was to make the transition from a desktop environment to the web, otherwise there would be no such thing as ViewState. Why would you need state for a standard website? You wouldn’t. Maybe for a shopping cart system, but a secured website and cookies fit the bill there.

There are enough third party controls out there with cool things that they do that WebForms will not go away, nor should it. For the longest time it was the only player on the block; having competition, even if from the same parent, can only make it better. As well, many organizations have a lot of time and effort invested into WebForms applications so why should it go away? It shouldn’t; it has its purposes and it works great for those.

MVC Strengths

A strength of MVC is its ability to deliver content through URL routing. Yes, I know that the routing engine is available to use through WebForms too, but I think it’s ability as an inherent part of the MVC system is a major strength. I mean, compare these potential URLs:

http://www.blah.com/DoSomething.aspx?action=blog&id=MVCPost

http://www.blah.com/Blog/MVCPost

Of those 2 URLs, which one is easier to read (from an end user POV)? Which one is easier to understand where you are? Definitely the second, which takes full advantage of the routing engine in MVC. As well, MVC focuses on strong separation of the view from the logic; WebForms… not so much (it can, but with many developers focusing on a technology instead of a best practice, you don’t see this as much).

Where Could They Be Used Together?

I could see both technologies being used to create a full deliverable solution:

  • A WebForms application being used to create the support interface for a content management system
  • MVC being used to deliver the public-facing result of the CMS

Why would I see it this way?

  • The CMS needs to be able to set content on multiple templates. Only authenticated users should be able to do this, not everyone who has access to the site. Being able to manipulate content (images, text content, page templates, activation and expiration dates of content) is inherent to application-style functionality. The ability to manipulate content seems much more in-place with the purpose of the WebForms infrastructure.
  • The public-facing site (content delivery) would be much more suited to MVC. MVC merely has to extract the information it needs and provide it through the controller and model to the view, which handles all UI elements. For the most part, modules within a CMS are (should be) reusable and as such just need a mechanism to display them, and MVC provides that quite easily.

Now, I am not saying that you cannot or should not use one technology for the infrastructure or public delivery over the other; it’s personal preference. However, I think MVC gives a few extra bonuses for a public site that needs value to be applied to it:

  • Native routing engine that gives more user-friendly URLs, which makes metrics gathering that much more simpler to do (if done client-side)
  • Page settings are easier to control (page title, etc.)
  • No worries about third-party WebForms controls displaying strange raw HTML (it has been known to happen)
  • Adding a new visual piece of functionality does not inherently mean changing every element of the application, whereas with WebForms you may have to do so (not always)
  • Full control over the UI means the potential for enhanced search metrics

I am focused greatly on metrics, usability, and enhancing a website with work these days so thinking of how I can enhance an application… well, MVC seems to have these things more “out of the box” which means faster turnaround, which means more value, which also leads to more work to make things better. WebForms has its place, but public-facing content delivery sites (IMO) is not one of them.

There is a mantra out there in software these days: “The right tool for the job.” It really takes an understanding of the technologies out there to make this call, and knowing its capabilities really seems to help. Having only a one-sided view limits the potential for enhancement and value; you really need to understand what is going on and go in with the mindset of delivering something quality, but also with a system that can help make things better.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

ASP.NET MVC | ASP.NET | WebForms

Comments

Add comment


 

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

TextBox

RecentPosts