• Sections

  • What's Wrong with ASP.NET Web Forms?

    Traditional ASP.NET Web Forms was a great idea, and opened a whole new world to classic ASP developers. However, real-world use of Web Forms has revealed a variety of weaknesses:
    • Limited control over HTML: Server controls render themselves as HTML, but not ideally. Prior to version 4 of the .NET framework, the output of server controls often failed to comply with web standards. They also did not make good use of CSS. Finally, they generated unpredictable and complex ID values which are hard to access using JavaScript.
    • Weight of ViewState: Web Forms rely heavily on ViewState to maintain state across requests, which often results in giant blocks of data being transferred over the line. In many real-world applications, the ViewState can reach hundreds of kilobytes, which goes back and forth with every request. Even ASP.NET AJAX, you suffer the same problem because the ViewState data still has to be sent back and forth with each asynchronous request.
    • False sense of separation of concerns: ASP.NET's code-behind model allows developers to take application code out of its HTML markup and place it into a code-behind class. In reality, this encourages developers to mix presentation code (e.g., manipulation of the server-side control tree) with their application logic (e.g., manipulation of database data). This would all be included in these code-behind classes which ended up being enormous in size. Without a better separation of concerns, the result was often incomprehensible and brittle.
    • Page life cycle: Many developers get ViewState errors or find that some event handlers fail to execute when attempting to manipulate the control hierarchy at runtime. This is due to the complicated and delicate page life cycle, which connects client-side events with server-side event handler code.
    These are just a few of the issues faced by developers when creating applications using Web Forms. Now enter the MVC architecture. Thanks to its adoption of the MVC architecture, the ASP.NET MVC Framework provides a greatly improved separation of concerns. The MVC pattern dates back to 1978 and the Smalltalk project at Xerox PARC. User interaction with an MVC application follows a natural cycle: the user takes an action, in response the application changes its data model and then delivers an updated view to the user. This is a series of HTTP requests and responses, which makes it a nice fit for web applications.

    Extensibility
    The ASP.NET MVC framework is extensible. It is built as a series of components that can be easily replaced with a component of your own creation. You have three options:
    • Use the default implementation of the component
    • Derive a subclass of the default implementation so you can modify its behavior
    • Completely replace the component with a new implementation.
    Tight Control over HTML and HTTP
    In today's world, producing clean, standards-compliant markup is important. With ASP.NET MVC you can do just that. The framework includes built-in HTML helper methods produce standards-compliant output, but it also encourages you to build simple, elegant markup styled with CSS.

    ASP.NET MVC pages don't contain any ViewState data, thus, they can be hundreds of kilobytes smaller than pages generated by ASP.NET Web Forms. This efficient use of bandwidth offers a great improvement to the end user experience, despite today's fast broadband connections.

    ASP.NET MVC works with, not against, HTTP. You have complete control over the requests passing between browser and server, which allows you to fine-tune your user experience. There aren't any automatic postbacks to interfere with client-side state, which makes AJAX easy.

    Powerful Routing System
    Also known as URL Rewriting, clean or Friendly URLs have become quite important. Instead of URLs like /MyApp/Calendar/Default.aspx?action=show%20event&eventid=18457, it's far more professional to use /calendar/events/18457-developers-convention.

    Because you're reading this, I think it's safe to assume that you're a developer, so I don't need to go into details about why the second URL structure is better. Simply put, it's more readable by humans, it offers keywords that help with search engine rankings, and it doesn't reveal the technical details, folder, and file name structure of your application.

    In earlier frameworks, clean URLs were hard to implement. ASP.NET MVC uses the System.Web.Routing facility to give you clean URLs by default. You have total control over the structure of your URLs and how they map to your controllers and actions.

    Built on the ASP.NET Platform
    ASP.NET MVC is based on the .NET platform. This means you can write code in any .NET language and use the same API features in the extensive .NET class library and other third-party .NET libraries. You can still utilize features such as master pages, forms authentication, membership, roles, profiles and more, to reduce the amount of code you need to develop yourself.

    Hopefully by now, you have a good understanding of the benefits ASP.NET MVC possess over ASP.NET Web Forms. If you are really interested in learning more, I highly recommend reading Pro ASP.NET MVC 2 Framework by Steven Sanderson, which is where I found most of the information in this article. This book walks you through building an actual MVC application and contains a lot of useful information.
    Comments 1 Comment
    1. don94403's Avatar
      Great article! Although I'm not presently doing any ASP .NET work, I may need to at some point, and this is a reference I will keep for later study.

    SEO by vBSEO