Evjen c34.tex V1 - 01/28/2008 4:20pm Page 1566 Chapter 34: Packaging and Deploying ASP.NET Applications installer program that can run side events, provide dialogs, and even install extra items such as databases and more. Just remember that when working on the installation procedures for your Web applications, you should be thinking about making the entire process logical and easy for your customers to understand. You do not want t o make people’s lives too difficult when they are required to programmatically install items on another machine. 1566 Evjen bapp01.tex V1 - 01/28/2008 4:31pm Page 1567 Migrating Older ASP.NET Projects In some cases, you build your ASP.NET 3.5 applications from scratch — starting everything new. In many instances, however, this is not an option. You need to take an ASP.NET application that was previously built on the 1.0, 1.1, or 2.0 versions of the .NET Framework and migrate the application so that it can run on the .NET Framework 3.5. This appendix focuses on migrating ASP.NET 1.x or 2.0 applications to the 3.5 framework. Migrating Is Not Difficult Be aware that Microsoft has done a lot of work to ensure that the migration process from ASP.NET 1.x is as painless as possible. In most cases, your applications run with no changes needed. When moving a 1.x or 2.0 application to 3.5, you don’t have to put the ASP.NET application on a new server or make any changes to your present server beyond installing the .NET Framework 3.5. After you install the .NET Framework 3.5, you see the framework versions on your server at C:\WINDOWS\Microsoft.NET\Framework, as illustrated in Figure A-1. In this case, you can see that all five official versions of the .NET Framework installed including v1.0.3705, v1.1.4322, v2.0.50727, v3.0, and v3.5. Evjen bapp01.tex V1 - 01/28/2008 4:31pm Page 1568 Appendix A: Migrating Older ASP.NET Projects Figure A-1 Running Multiple Versions of the Framework Side by Side From this figure, you can see that it is possible to run multiple versions of the .NET Framework side by side. ASP.NET 1.0, ASP.NET 1.1, ASP.NET 2.0, and ASP.NET 3.5 applications can all run from the same server. Different versions of ASP.NET applications that are running on the same server run in their own worker processes and are isolated from one another. Upgrading Your ASP.NET Applications When you install the .NET Framework 3.5, it does not remap all your ASP.NET applications so that they now run off of the new framework instance. Instead, you selectively remap applications to run off of the ASP.NET 3.5 framework. To accomplish this task if you are migrating ASP.NET 1.x applications to ASP.NET 2.0, you use the ASP.NET MMC Snap-In that is a part of the .NET Framework 2.0 install. You get to this GUI-based administration application by right-clicking and selecting Properties from the provided menu using Windows XP when you are working with your application domain in Microsoft’s Internet Information Services (IIS). After selecting the MMC console (the Properties option), select the ASP.NET tab and you are provided with something similar to what is shown in Figure A-2. 1568 Evjen bapp01.tex V1 - 01/28/2008 4:31pm Page 1569 Appendix A: Migrating Older ASP.NET Projects Figure A-2 You can see from this figure that an option exists for selecting the application’s ASP.NET version (the top-most option). This allows you to select the version of the .NET Framework in which this ASP.NET application should run. In this case, the Wrox application on my machine was retargeted to the 2.0 release of ASP.NET when I selected 2.0.50727 in the drop-down list. You should always test your older ASP.NET application by first running on the newer version of ASP.NET in a developer or staging environment. Do not change the version to a newer version on a production system without first testing for any failures. Figure A-3 1569 Evjen bapp01.tex V1 - 01/28/2008 4:31pm Page 1570 Appendix A: Migrating Older ASP.NET Projects If you are not ready to upgrade your entire application to a newer version of ASP.NET, one option is to create additional virtual directories in the root virtual directory of your application and target the portions of the application to the versions of the .NET Framework that you want them to run on. This enables you to take a stepped approach in your upgrade process. If you are upgrading from ASP.NET 2.0 to ASP.NET 3.5, there really is very little that you have to do. It is true that the System.Web DLL in both versions of the framework is the same. The major differences between these two versions of the framework for ASP.NET are the use of a different language compiler and the inclusion of the System.Core and the System.Web.Extensions DLLs. Thedifferencesareevenmoreself-evidentwhen working with the new IIS Manager on Windows Vista. From this management tool, you can see that the DefaultAppPool is running off the same ver- sion 2.0.50727 of the .NET Framework, as shown in Figure A-3. Upgrading your application to ASP.NET 3.5 using Visual Studio 2008 will cause the IDE to make all the necessary changes to the application’s configuration file. This is illustrated later in this appendix. When Mixing Versions — Forms Authentication If you have an ASP.NET application that utilizes multiple versions of the .NET Framework then, as was previously mentioned, you must be aware of how forms authentication works in ASP.NET 2.0 and 3.5. In ASP.NET 1.x , the forms authentication process uses Triple DES encryption (3DES) for the encryption and decryption process of the authentication cookies. ASP.NET 2.0 and 3.5, on the other hand, uses an encryption technique — AES (Advanced Encryption Standard). AES is faster and more secure. However, because the two encryption techniques are different, you must change how ASP.NET 3.5 generates these keys. You can accomplish this by changing the < machineKey > section of the web.config in your ASP.NET 3.5 application so that it works with Triple DES encryption instead (as presented in Listing A-1). Listing A -1: Changing your ASP.NET 3.5 application to use Triple DES encryption <configuration> <system.web> <machineKey validation="3DES" decryption="3DES" validationKey="1234567890123456789012345678901234567890" decryptionKey="1234567890123456789012345678901234567890" /> </system.web> </configuration> By changing the machine key encryption/decryption process to utilize Triple DES, you enable the forms authentication to work across an ASP.NET application that is using both the .NET Framework 1.x and 3.5. Also, this example shows the validationKey and decryptionKey attributes using a specific set of keys. These keys should be the same as those you utilize in your ASP.NET 1.x application. 1570 Evjen bapp01.tex V1 - 01/28/2008 4:31pm Page 1571 Appendix A: Migrating Older ASP.NET Projects It is important to understand that you are not required to make these changes when you are upgrading an ASP.NET 2.0 application to ASP.NET 3.5 because both are enabled to use AES encryption and are not using Triple DES encryption. If you are mixing an ASP.NET 1.x application along with ASP.NET 2.0 and 3.5, then you are going to have to move everything to use Triple DES encryption, as shown in Listing A-1. Upgrading — ASP.NET Reserved Folders As described in Chapter 1 of this book, ASP.NET 3.5 includes a number of application folders that are specific to the ASP.NET framework. In addition to the \ Bin folder that was a reserved folder in ASP.NET 1.x, the following folders are all reserved in ASP.NET 2.0 and 3.5: ❑ \ Bin : This folder stores the application DLL and any other DLLs used by the application. This folder was present in both ASP.NET 1.0 and 1.1. It is also present in both ASP.NET 2.0 and 3.5. ❑ \ App_Code : This folder is meant to store your classes, .wsdl files, and typed datasets. Any items stored in this folder are automatically available to all the pages within your solution. ❑ \ App_Data : This folder holds the data stores utilized by the application. It is a good, central spot to store all the data stores used by your application. The \ App_Data foldercancontainMicrosoft SQLExpressfiles( .mdf files ), Microsoft Access files ( .mdb files ),XMLfiles,andmore. ❑ \ App_Themes : Themes are a new way of providing a common look-and-feel to your site across every page. You implement a theme by using a .skin file , CSS files, and images used by the server controls of your site. All these elements can make a theme, which is then stored in the \ App_Themes folder of your solution. ❑ \ App_GlobalResources : This folder enables you to store resource files that can serve as data dic- tionaries for your applications if these applications require changes in their content (based on things such as changes in culture). You can add Assembly Resource Files ( .resx )tothe \ App_GlobalResources folder, and they are dynamically compiled and made part of the solution for use by all the .aspx pages in the application. ❑ \ App_LocalResources : Quite similar to the \ App_GlobalResources folder, the \ App_ LocalResources folder is a pretty simple method to incorporate resources that can be used for a specific page in your application. ❑ \ App_WebReferences : You can use the \ App_WebReferences folder and have automatic access to the remote Web services referenced from your application. ❑ \ App_Browsers : This folder holds .browser files, which are XML files used to identify the browsers making requests to the application and to elucidate the capabilities these browsers have. The addition of the App_ prefix to the folder names ensures that you already do not have a folder with a similar name in your ASP.NET 1.x applications. If, by chance, you do have a folder with one of the names you plan to use, you should change the name of your previous folder to something else because these ASP.NET 3.5 application folder names are unchangeable. ASP.NET 3.5 Pages Come as XHTML ASP.NET3.5,bydefault,constructsitspagestobeXHTML-compliant.Youcanseethesettingfor XHTML 1.0 Transitional in the Visual Studio 2008 IDE. This is illustrated in Figure A-4. 1571 Evjen bapp01.tex V1 - 01/28/2008 4:31pm Page 1572 Appendix A: Migrating Older ASP.NET Projects Figure A-4 In this case, you can see that you have a list of options for determining how the ASP.NET application outputs the code for the pages. By default, it is set to XHTML 1.0 Transitional (Netscape 7, Opera 7, Internet Explorer 6 ). You can also make a change to the web.config file so that the output is not XHTML-specific (as illustrated in Listing A-2). Listing A -2: Reversing the XHTML capabilities of your ASP.NET 3.5 application <configuration> <system.web> <xhtmlConformance mode="Legacy" /> </system.web> </configuration> Setting the mode attribute to Legacy ensures that XHTML is not used, but instead, ASP.NET 3.5 defaults to what was used in ASP.NET 1.x. It is important to note that using the Legacy setting as a value for the mode attribute will sometimes cause you problems for your application if you are utilizing AJAX. Some of the symptoms that you might experience is that instead of doing a partial page update (as AJAX does), you will get a full-page postback instead. This is due to the fact that the page is not XHTML compliant. The solution is to set the mode property to Traditional or Strict and to make your pages XHTML compliant. 1572 Evjen bapp01.tex V1 - 01/28/2008 4:31pm Page 1573 Appendix A: Migrating Older ASP.NET Projects If you take this approach, you also have to make some additional changes to any new ASP.NET 3.5 pages that you create in Visual Studio 2008. Creating a new ASP.NET 3.5 page in Visual Studio 2008 produces the results illustrated in Listing A-3. Listing A -3: A typical ASP.NET 3.5 page <%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> </div> </form> </body> </html> From this, you can see that a < !DOCTYPE > element is included at the top of the page. This element signifies to some browsers (such as Microsoft’s Internet Explorer) that the page is XHTML-compliant. If this is not the case, then you want to remove this element altogether from your ASP.NET 3.5 page. In addition to the < !DOCTYPE > element, you also want to change the < html > element on the page from: <html xmlns="http://www.w3.org/1999/xhtml"> to the following: <html> The original also signifies that the page is XHTML-compliant (even if it is not) and must be removed if your pages are not XHTML-compliant. No Hard-Coded .js Files in ASP.NET 3.5 ASP.NET 1.x provides some required JavaScript files as hard-coded .js files. For instance, in ASP.NET a JavaScript requirement was necessary for the validation server controls and the smart navigation capa- bilities to work. If you are utilizing either of these features in your ASP.NET 1.x applications, ASP.NET could pick up the installed .js files and use them directly. These .js files are found at C: \ WINDOWS \ Microsoft.NET \ Framework \ v1.0.3705 \ ASP.NETClientFiles . Looking at this folder, you see three .js files — two of which deal with the smart navigation feature ( SmartNav.js and SmartNavIE5.js ) and one that deals with the validation server controls 1573 Evjen bapp01.tex V1 - 01/28/2008 4:31pm Page 1574 Appendix A: Migrating Older ASP.NET Projects ( WebUIValidation.js ). Because they are hard-coded .js files, it is possible to open them and change or alter the code in these files to better suit your needs. In some cases, developers have done just that. If you have altered these JavaScript files in any manner, you must change some code when migrating your ASP.NET application to ASP.NET 2.0 or 3.5. ASP.NET 3.5 dynamically includes .js files from the System.Web.dll instead of hard-coding them on the server. In ASP.NET 3.5, the files are included via a new handler — WebResource.axd. Converting ASP.NET 1.x Applications in Visual Studio 2008 As previously mentioned, if you have a pre-existing ASP.NET 1.x application, you can run the application on the ASP.NET 2.0 runtime by simply making the appropriate changes in IIS to the application pool. Using the IIS manager or the MMC Snap-In, you can select the appropriate framework on which to run your application from the provided drop-down list. ASP.NET 3.5 applications work with the Visual Studio 2008 IDE. If you still intend to work with ASP.NET 1.0 or 1.1 applications, you should keep Visual Studio .NET 2002 or 2003, respectively, installed on your machine. Installing Visual Studio 2008 gives you a complete, new copy of Visual Studio and does not upgrade the previous Visual Studio .NET 2002 or 2003 IDEs. All copies of Visual Studio can run side by side. If you want to run ASP.NET 1.x applications on the .NET Framework, but you also want to convert the entire ASP.NET project for the application to ASP.NET 3.5, you can use Visual Studio 2008 to help you with the conversion process. After the project is converted in this manner, you can take advantage of the features that ASP.NET 3.5 offers. To convert your ASP.NET 1.x application to an ASP.NET 3.5 application, you simply open up the solution in Visual Studio 2008. This starts the conversion process. It is important to note that Visual Studio 2008 converts the application to an ASP.NET 2.0 application first and then asks if you want to take the extra step to convert the application to an ASP.NET 3.5 application. When you open the solution in Visual Studio 2008, it warns you that your solution will be upgraded if you continue. It does this by popping up the Visual Studio Conversion Wizard, as presented in Figure A-5. Notice that the upgrade wizard has been dramatically improved from Visual Studio .NET 2003 to this newer one provided by Visual Studio 2008. To start the conversion process of your ASP.NET 1.x appli- cations, click the Next button in the wizard. This example uses the open source Issue Tracker Starter Kit — an ASP.NET 1.1 starter kit found on the ASP.NET Web site at www.asp.net . The first step in the process is deciding whether you want the Visual Studio 2008 Conversion Wizard to create a backup of the ASP.NET 1.1 application before it attempts to convert it to an ASP.NET 2.0 application (remember that it first converts to an ASP.NET 2.0 application before asking you to convert it to an ASP.NET 3.5 application). Definitely, if this is your only copy of the application, you want to make a back-up copy even though this conversion wizard does a good job in the conversion process. The conversion wizard also enables you to specify the location where you want to store the back-up copy. This step is presented in Figure A-6. 1574 Evjen bapp01.tex V1 - 01/28/2008 4:31pm Page 1575 Appendix A: Migrating Older ASP.NET Projects Figure A-5 Figure A-6 1575 . new ASP. NET 3. 5 pages that you create in Visual Studio 2008. Creating a new ASP. NET 3. 5 page in Visual Studio 2008 produces the results illustrated in Listing A -3. Listing A -3: A typical ASP. NET. migrating your ASP. NET application to ASP. NET 2.0 or 3. 5. ASP. NET 3. 5 dynamically includes .js files from the System.Web.dll instead of hard-coding them on the server. In ASP. NET 3. 5, the files are included. the .NET Framework side by side. ASP. NET 1.0, ASP. NET 1.1, ASP. NET 2.0, and ASP. NET 3. 5 applications can all run from the same server. Different versions of ASP. NET applications that are running