I have a Web Forms custom application. Should I upgrade to ASP.NET MVC now, or wait?

Web Forms was _very_ different from Classic ASP, which, at the time, was called just ASP. Or ASP 3.0, which had some differences from ASP 2.0, for those who remember. ASP 1.0 was short-lived, and it largely remains a blur between the IDC/HTX technology that graced IIS 2.0, and ASP 2.0, which became very popular.

The programming model of Web Forms was radically different from ASP.  In fact, it very closely resembled the programming model of Visual Basic (VB) 6, which enabled the developer to visually position controls or UI elements on a screen and then double-click buttons in order to quickly write some code to execute when that button is pressed. For those who remember .Net 1.0, you will remember that ASP.NET used absolute CSS positioning to emulate grid-like placement of UI elements on the screen.  That didn’t last long, and ASP.NET 1.1 changed the default layout to “flow layout”, which is the way the web works anyway.

Let’s review.  In the mid-90′s, you programmed dynamic web applications on Windows/IIS servers using code that largely looked like this.

Datasource:ecommerce
   Template:ListOrders.htx
   SQLStatement:SELECT *
   +FROM Orders
   +WHERE Orders.Status='%OrderStatus%';

 From an HTML page, you just made a form that posted “OrderStatus” from a select box to ListOrders.idc.  This file executed the SQL statement against the ecommerce DSN registered on the server – most likely hooking into an ODBC data source to a main frame, Sybase, or Access database.  The HTX file was the next web page that was rendered and might have looked like this (with some HTML formatting around it, of course. 

<%begindetail%>
<%OrderId%>
<%if CustomerName eq ""%>   <%else%><%CustomerName%> <%endif%> 
<%enddetail%>

 We can clearly see the lineage from this, up through Classic ASP, into ASP.NET with Web Forms, as well as through the first two version of ASP.NET MVC.  The new Razor view engine with ASP.NET MVC 3 & 4 does away with the beloved and cursed “code nugget” (<%= %>) that started in the mid-nineties with the IDC/HTX technology.

So should I upgrade my Web Forms application to MVC?

I explained the bit of history above so that you would have some context to answer this question for yourself.  To answer this question, you should know a bit about the run times.

With Classic ASP, you are likely to have code written in VBScript using COM+ components.  It is possible your applications used JScript, but this was more rare, although supported nicely.  These applications run just fine in Windows/IIS and in Azure, but you cannot have them run in the same memory space as ASP.NET.  .Net was a hard break from the COM world of the late 90′s.  Contrast that with ASP.NET 1.0-4.5, and Web Forms, ASMX, ASP.NET MVC, and Web API.  All of these technologies can run in the same website within IIS and share the memory.  This is very powerful because we are not forced to answer the question of whether to rewrite or not.  We can do both.  We can keep the Web Forms features and functions that work just fine and add on to the application using ASP.NET MVC and Web API.  In fact, some teams are using HTML5 on top of ASP.NET MVC to write touch-based tablet apps that can be synced and used off-line.

The answer

It is rarely a good idea to trash your current application and start over.  Too much has been invested, and if any of it is working properly and serving the business, then keep it.  To keep it, just add onto the code base with ASP.NET MVC.  You can rewrite some of the screens if there is a lot to be desired there, but because Web Forms and MVC work seamlessly together in the same web application, it’s a touch sell from a business perspective to write software just to have it behave the same way.  If these existing functions need to be exposed to tablets or phones, then it’s fairly easy to create new MVC screens with HTML5 and use some of the same business logic (if well factored), or at least the same database tables with rewritten business logic.  If a native phone app is in order, Web API can serve as the HTTP web services to serve and receive data.  These web services run nicely integrated with an existing Web Forms application.

There is an estimated 4 million web forms applications and websites out there (and probably many more that are not on publicly indexable web servers – to be counted).  Enhancing an existing Web Forms application with the newer technologies can be a powerful way to preserve the deep investments made this far.

 

Written by

Leveraging past experience managing software organizations and delivering solutions for clients, Jeffrey helps to deliver clarity, measurement, and control for software organizations as they seek to develop and operate mission-critical software systems that help them maintain a competitive advantage. Clear Measure delivers a full lifecycle of services based around Microsoft software technologies. Jeffrey has been recognized by Microsoft as a “Microsoft Most Valuable Professional” (MVP) for five years. He has spoken and facilitated at industry conferences such as VSLive, DevTeach, the Microsoft MVP Summit, various ALT.NET conferences, and Microsoft Tech Ed. He also speaks to user groups around the country as part of the INETA Speakers’ Bureau. A graduate of Texas A&M University, an Eagle Scout, and an Iraq war veteran, Jeffrey holds too many certifications to list, has published many magazine articles , and he has written three editions of his book.

11 Comments to “I have a Web Forms custom application. Should I upgrade to ASP.NET MVC now, or wait?”

  1. Alper says:

    it’s a touch sell => it’s a tough sell ?

  2. Sean Feldman says:

    Hi Jeffrey,
    Good post, and very accurate. One aspect you haven’t addressed is pains associated with maintaining (and perhaps extending) WebForms applications that traditionally had no testing at all. You do state that some of the rework is possible by leveraging same business logic “if well factored”, though very often with web forms tendency was to mix presentation and other logics in code behind.
    Moving forward, I would imagine people try to get away from adding to old webforms apps, rather than adding to it.

    • kdsdata says:

      re Sean Feldman: I can understand your comments about getting away from old technology, but the issue is less simple than stated. I maintain websites that are still based on Classic ASP. They are all based on the same original software template. Users (organizations) all have their own customization requirements, each of these being relatively small programming efforts. As the language is well known to me it is very much simpler to keep the Classic ASP platform intact. To add any ASP.NET layer would complicate things. Not because of the individual degree of difficulty, but because of the replication of the issue to the number of applications.

      However, on the one hand it’s easier to keep working with the old code. On the other hand, the down-side is that personal programming skills don’t keep pace with advancing technology.

      For new application my choice is ASP.NET MVC. My other issue is “do I also switch away from VB.NET”. But that is a totally other kettle of fish.

    • Henry says:

      Yeah, I agree with you Sean. I’ve tried every which way to ‘keep’ the old webforms app and ‘merge’ in new MVC pages as needed, but the new structure of MVC is so different from the tightly knit Webforms style that it’s become clear to me the we need to rewrite our app on a clean MVC app and just keep the same database structure (and port over the logic where possible).

    • @Sean,
      You are right. I didn’t address that. Without understand specifics of an application, at the highest level, we can partition the web project into old/new. Using the routing capabilities, we can establish a new URL level which will represent new MVC pages, leaving all the old Web Forms intact. This works even for very messy applications.

      @Henry,
      With your situation, I wouldn’t try to change any of your Web Forms code. I would leave it in place and create an MVC area to work within. As you add pages, they can go here, and you can use the same database you have come to rely on. You can pick your battles on leveraging existing code vs. writing logic from scratch. Drop me a line if you need any help.

  3. Robert J. Good says:

    Great post. I often weight the pros/cons of upgrading to MVC.

    My rules are:
    1. All new screens (that don’t reuse existing custom UI user controls): MVC.
    * Given the developer has the MVC skills
    2. Any screen/site that require too much maintenance: MVC.
    * Its worth the rewrite time, rather than paying slowly over years.
    3. Low maintenance screens that are working properly: Leave alone.

    Maintenance and stability wise, MVC is far superior to Web Forms (or most other non-Microsoft technologies.)

    I did a lines-of-code count on the same screen coded in web forms vs. MVC…here are the results:

    HTML Lines
    * Web Forms: 184
    * MVC: 68

    VB Lines of Code:
    * Web Forms 703
    * MVC 13

    Pages and User Controls:
    * Web Forms: 6
    * MVC: 3

    Hope this helps!

    • Robert,
      Great points! Indeed there are some pages that don’t need to be touched at all.

    • kdsdata says:

      Thanks Robert. Those stats are very good information and convincing enough to consider a change up. For customization work I would adjust the criteria:

      1. if it a small customiztion job, keep the classic code,
      2. if it’s a mid to large job, switch to MVC.

      Again thanks for the stats.

  4. Roger says:

    MVC is like “secrets inside secrets”. For me is more evil´s added to the already full pandora´s box that is web development…

  5. Schmulik Raskin says:

    Your posts mostly concerns someone who has decided to use ASP.NET MVC, and is wondering what to do with existing WebForms code. However, that is not the complete picture, considering that there have been advances in Web Forms, especially 4.5, like Routing, ModelBinding and strongly-typed Data controls.
    Make no mistake, I am a huge fan of MVC and wouldn’t use WebForms ever again. But for a post that provides guidance on the subject, it should provide this information too. Thanks for the article.