Upgrading Web Applications
How do you upgrade your Visual Basic 6.0 web applications to .NET? Although there are different solutions, you should take into consideration that manual effort will probably be required. For instance, to upgrade VB6 ActiveX documents to .NET, it is necessary to rewrite them to Web user controls in order to recreate similar functionality. VB6 Web classes, on the other hand, can be at least partially upgraded to .NET automatically with the help of the Visual Basic Upgrade Wizard and the WebClass compatibility runtime. Please review the techniques presented in this chapter to address issues with upgrading these types of Web-based applications to Visual Basic .NET.
When converting from Visual Basic 6.0 to Visual Basic.NET, are my ActiveX documents supported?
No, Visual Basic 6.0 ActiveX documents are not supported in Visual Basic .NET. You can still interoperate with ActiveX documents from your Visual Basic .NET Web applications, but development should be maintained in Visual Basic 6.0.
What upgrade options do I have when dealing with applications that use ActiveX documents?
- You can use ActiveX documents from your Visual Basic .NET Web applications through interoperability, but development must be maintained in Visual Basic 6.0. You can navigate from a Visual Basic .NET Web Form to a Visual Basic 6.0 ActiveX document, and vice-versa.
- You can rewrite your ActiveX documents as Web user controls. You will have to include the new controls in a Web Form to simulate the behavior of your ActiveX documents.
- You can create a Windows Form control that corresponds to the original ActiveX document and then host it in Microsoft Internet Explorer. This approach takes advantage of the similar features in both the source and target components, but nonetheless is limited with respect to deployment and compatibility.
How are Visual Basic 6.0 Web Classes upgraded to VB.NET?
In Visual Basic 6.0, WebClass projects (also known as IIS application projects) are used to create Web applications based on ASP technology. In Visual Basic .NET, ASP.NET Web application projects are used to create Web applications based on the newer ASP.NET technology. When a Visual Basic 6.0 WebClass project is upgraded to Visual Basic .NET, it is converted to an ASP.NET Web application project.
How does the ‘StateManagement’ property differ from Visual Basic 6.0 to Visual Basic .NET?
In Visual Basic .NET, ASP.NET Web applications do not have a StateManagement property. Any code related to state management will need to be replaced; there are many options for this. Some options involve keeping information on the client (for example, directly in the page or in a cookie), and others involve storing information on the server between round trips.
In a VB to .NET conversion, what techniques can be used if I have decided to keep the information on the client?
If you decide to store your instance on the client, you can use some of the following techniques:
- View state. The control.ViewState property provides a dictionary for retaining values between multiple requests for the same page. This information is automatically stored. When the page is processed, the current state of the page and controls is hashed into a string and saved in the page as a hidden field. When the page is posted back to the server, the page parses the view state string at page initialization and restores property information on the page.
- Hidden form fields. You can create hidden fields on a form that are not visibly rendered by the browser. With this technique, you can set properties just as you can with a standard control. When the page is submitted to the server, the content of the hidden field is sent in the HTTP Form collection along with the values of the other controls, which allows you to store information directly in the page by way of the hidden fields.
- Cookies. You can use cookies to store information about a particular client, session, or application. The cookies are saved on the client device, and when the browser requests a page, it sends the information in the cookie along with the requested information. The server can read the cookie and extract the necessary value.
- Query strings. You use query strings to maintain some state information, but they are limited to the capacity of the browser and client devices. This imposes a 255 character limit on the length of the URL. For query string values to be available during page processing, you must submit the page using an HTTP GET method. The consequence of this is that you cannot take advantage of this option if a page is processed in response to an HTTP POST method.
And if I decide to store the information on the server, what methods can be used?
- Application state. With ASP.NET, you can save values using application state (an instance of the HttpApplicationState class for each active Web application). Application state is a global storage mechanism accessible from all pages in the Web application and is useful for storing information that needs to be maintained between server round trips and between pages. Application state is a key-value dictionary structure created during each request to a specific URL. You can add your information to this structure to store it between page requests.
- Session state. With ASP.NET, you can save values using session state (an instance of the HttpSessionState class for each active Web application session).
- Database support. You can maintain the state of the page using database technology when you are storing a large amount of information. Database storage is particularly useful for maintaining long-term state or state that must be preserved even if the server must be restarted. The database approach is often used in conjunction with cookies.
What Visual Basic 6.0 WebClass events are not supported in ASP.NET?
Visual Basic 6.0 WebClass events that are not supported in ASP.NET include Initialize, BeginRequest, EndRequest, and Terminate. These event procedures will be upgraded by the upgrade wizard, but they will not be called at run time. After upgrading, you will need to move any code in these events to equivalent ASP.NET events, such as Init or Unload.