Summary of several issues in upgrading ASP.NET 1.0 to ASP.NET 2.0
Author:Eve Cole
Update Time:2009-06-30 16:06:42
I have upgraded the original 1.1 project in the past few days and found some problems. I will summarize them here and remind friends who have not had time to upgrade or are ready to upgrade to avoid detours and waste time during the upgrade process.
1. The processing form of Global.asax file is different, and errors will occur after conversion. In vs2003, Global.asax has a code post-file. Under 2.0, the code separation file is moved to the App_Code directory so that it can automatically become available through the application. Access any ASP.NET page in the program. The "Code-behind" attribute will be removed from directives in ASAX files. vs2005 writes the code directly in Global.asax. Therefore, you need to delete the converted files and re-add them, and copy the corresponding code.
There is no project file in 2.2.0. In a 1.1 application, the project file contains build settings, references to external assemblies, and a list of files in the project. In 2.0 applications, version settings and file lists are no longer needed because all files in the Web project directory are considered part of the Web project.
3. Code separation mode.
In ASP.NET 1.1, code separation mode separates content (such as test.aspx) from code (such as test.aspx.cs). Content pages inherit from code-separated pages, which contain user- and designer-generated code.
ASP.NET 2.0 enhances the code separation mode through the use of partial classes, using the partial keyword to separate the code of a single class into two separate files. It allows a class to span multiple files. In the new code-separated mode, the content page inherits from the compiled class, which consists of the corresponding code-separated page and the automatically generated stub file that defines the field declarations for the controls used in the content page. This change separates automatically generated code from the user's code and makes the code separation page significantly smaller and cleaner. The partial class structure also reduces the risk of accidentally breaking the page by editing the code generated by the designer.
If an error occurs, check whether there is a partial keyword, otherwise add the partial keyword.
4. Grammar check. The asp.net1.1 program will not check the syntax errors in aspx, aspcx and other files when compiling, while vs2005 will check the syntax in all aspx, aspcx and other files in the project when compiling, so if there are syntax errors, it will cause compilation Unable to pass.
5. Control declaration. If all controls are declared on the .aspx page, delete all control declarations from the code separation file, otherwise an error will be reported: Duplicate definition.
6. (C# only) Move the event hooking code from the InitialzeComponent function in the code split file into the .aspx page. Note that this action does not apply to automatically called events, including Page_Init, Page_Load, Page_DataBind, Page_PreRender, Page_Unload, Page_Error, Page_AbortTransaction, and Page_CommitTransaction.
7. Deployment method (precompiled, full compiled, updatable site, etc.). In 1.x, Web applications were precompiled and deployed as one large assembly. Content pages (*.aspx) are not compiled on the server, but can be edited on the server. With the new page compilation mode and directory structure, you can use a variety of different configurations to deploy ASP.NET 2.0 applications. In one case, you can precompile all ASPX pages and deploy a Web application consisting of fully compiled assemblies. In this mode, you cannot easily change the application on the server. Alternatively, you can deploy your application without precompiling any code. In this configuration, you can change .aspx pages, code-separate files, or any other code in the application directly on the server. When a user requests a page on the server, the page is dynamically compiled.
8. Change all CodeBehind properties in the .aspx page to CodeFile properties
CodeBehind: Specifies the name of the compiled file that contains the classes associated with the page. This property cannot be used at runtime.
This property is provided for compatibility with previous versions of ASP.NET to implement code-behind functionality. In ASP.NET version 2.0, you should instead use the CodeFile property to specify the name of the source file, and the Inherits property to specify the fully qualified name of the class.
CodeFile
Specifies the path to the code-behind file referenced by the page. This property is used with the Inherits property to associate a code-behind source file with a web page. This property is only valid for compiled pages.
9. Move all independent code files and AssemblyInfo.cs to the App_Code directory.
However, after running the conversion wizard, you may find that some code separation files (for example, *.aspx.cs or *.ascx.vb) have been moved to the App_Code directory. This indicates that the content page of the code split file contains a malformed Codebehind directive and is not set up correctly. That is, the conversion wizard cannot determine whether the code split file is actually bound to a specific .aspx page.
10. Web Services In ASP.NET 1.x, Web services (.asmx) are automatically split into a blank header page (.asmx) and a code-separated file containing the actual methods.
Under Asp.net2.0:
• Move the code separation class to the App_Code directory so that it automatically becomes accessible from any ASP.NET page in the application.
• Change the CodeBehind property in the .asmx file to point to the new location.
(Note that code-separated files do not use local classes, so the CodeBehind attribute continues to be used.)
• Change all Default, Friend and Internal scope declarations to Public.
What kind of problems did you encounter during the upgrade process from 1.1 to 2.0? You can write it down so that everyone can learn together and avoid detours.