Converting ASP.NET Web Applications from .NET Framework 1.1 to 2.0 and Above

When converting an ASP.NET web application from version 1.1 of the Microsoft .NET Framework to version 2.0 and above, the Visual Studio Conversion Wizard will convert your web application into what is termed a Web Site. In Framework 2.0 and above, ASP.NET apps come in two flavours: Web Site and Web Application Project [1]. The basic difference is that a Web Site does not have a .csproj or a .vbproj file, whereas a Web Application Project does. An ASP.NET Web Site behaves more like a classic ASP application where you can simply add, rename and delete files in Windows Explorer and no manual compilation is required. An ASP.NET Web Application Project, on the other hand, is essentially the same as a 1.1 ASP.NET web application, where the file structure is defined in a project file, and the project needs to be compiled into a DLL.

After converting your application using the Visual Studio Conversion Wizard, you are given the option to further convert your application to a Web Application Project. To do so, in VS2005 or VS2008, right click the project and click Convert to Web Application Project.

Unfortunately things are not so straightforward. Besides creating a .csproj or .vbproj file, the process also does the following:

  • set AutoEventWireup to true in all .aspx Page directives
  • remove all event wiring (e.g., this.Load += new System.EventHandler(this.Page_Load)) from InitializeComponent()
  • add event handlers (e.g. OnClick="...") to control tags in .aspx files

I don’t know why Microsoft saw fit to do all this. For performance reasons AutoEventWireup should be set to false [2]. If you have a large web application (1000+ files) that needs to be converted from 1.1 to 2.0+, and you have set AutoEventWireup to false in all .aspx files, Visual Studio will reset AutoEventWireup to true for all your files. This is not so bad as you can do a global search-and-replace to set it back to false.

Fortunately there is a way to prevent Visual Studio from removing event wiring from InitializeComponent(). Before converting to Web Application Project, do a global rename of InitializeComponent() to something else, such as XInitializeComponent(). Then, after using Visual Studio to convert to Web Application Project, rename them back to InitializeComponent(). (This isn’t my idea, someone else thought of it). This workaround will also prevent Visual Studio from adding event handlers to control tags in .aspx files.

Notes

[1] MSDN: Introduction to Web Application Projects. Includes a detailed comparison between Web Application Projects and Web Site Projects.

[2] Microsoft Help and Support article ID 324151: “If performance is a key consideration, do not set the value of the AutoEventWireup attribute to true. The AutoEventWireup attribute requires the ASP.NET page framework to make a call to the CreateDelegate function for every ASP.NET Web Form page. Instead of using automatic hookup, you must manually override the events from the page.” See also Inside AutoEventWireup by K. Scott Allen.

16 April 2008 | Software engineering, ASP.NET | Comments

One Response to “Converting ASP.NET Web Applications from .NET Framework 1.1 to 2.0 and Above”

  1. 1 AlexM 17 August 2008 @ 11:20 am

    Your blog is interesting!

    Keep up the good work!

Comments:

  1.  
  2.  
  3.