Asp.net|request| Solutions | questions
migrating to ASP. Net:key Considerations
Jim Kieley
Microsoft Corporation
July 2001
Summary:This article explores some basic considerations for moving existing ASP applications to the ASP. NET environment as Quickl Y and efficiently as possible. (Printed pages)
Contents
Introduction
Compatibility Issues
Core API Changes
Structural Changes
Visual Basic Language Changes
Com-related Changes
Application Configuration Changes
State Management
Security-related Changes
Data Access
Preparation for ASP. NET
Summary
Introduction
Although the designers of microsoft®asp. NET have done a excellent job in preserving backward with ASP app Lications, there are a few key items you need to is aware of before undertaking the effort of moving a WEB application fro m ASP to ASP. NET. A solid understanding of the technologies that have changed or been introduced with the. NET Platform and ASP. A long way in making this process a whole lot easier.
This article explores a number of areas of change to give a clear understanding of the efforts involved into getting an ASP Application up and running in the ASP. NET environment. At the "Same time", it points out some of the new features of ASP. NET This can is leveraged to improve a existing applicat Ion. This are by no means a comprehensive look at all of the new features in ASP. Instead, it focuses on areas this you need to know now for successful migration.
I am assuming that since the majority to ASP applications use microsoft®visual basic®scripting Edition (VBScript), most of your would elect to migrate to ASP. NET using Visual Basic. Net. This isn't obviously requirement, but changing languages at the same time you decide to migrate'll take some Al effort and most likely would include design and architectural changes as.
Coexistence
Before we get into discussing specific compatibility and migration issues, it is important this you understand how ASP and ASP. NET can coexist. Both ASP and ASP. NET applications can run side by side on a server without adversely affecting. This is primarily due to the fact that separate file extensions (. asp versus. aspx) and separate configuration models (met Abase/registry versus xml-based configuration files) are used the between two. The two systems have totally separate processing.
It is entirely possible to have part of one application running ASP and another part of the same application running ASP. NET. This is very beneficial if you are need to move a large, rapidly changing site to ASP. Some would argue that you are better off porting and deploying the entire site all at once. This is the case for certain classes of WEB applications, but I I-I-There are a lot of sites out there where th Is may isn't feasible due to the sheer size, complexity, and rapid evolution of the site ' s content and presentation. After all, if your are sitting on a profitable Web site, chances are the people paying the bills won't allow you to stop Implementing their new features so, can move things over to this hot new technology. Additionally, if you are are going to put forth the effort to move to ASP. NET as a long-term investment, you'll want to use This is chance to make as many architectural and design improvements as can. For these TypEs of situations, coexistence using a phased-in approach is a absolute must.
Compatibility Issues
Migrating your application to ASP. However, it should not being that difficult either. ASP. NET is very much compatible with ASP. This is impressive given the fact, ASP. NET is a complete overhaul of ASP. The designers of ASP. NET had an initial goal of being percent, backwards with ASP compatible but subsequently to B ACK off this goal in favor of improving the platform for the long haul. Not to worry-the changes made were for the better and should not require a lot of work in your to implement. The actual changes made can is categorized into the following sections:
- Core API Changes
- Structural changes
- Visual Basic Language Changes
- com-related changes
- Application configuration Changes
- State management issues
- security-related changes
- Data Access
Each of these areas is discussed in detail.
Core API Changes
The core APIs of ASP consist of a few intrinsic objects (
Request,
Response,
Server, etc.) and their associated methods. With the exception of a few simple changes, this APIs continue to function correctly under ASP. All of the changes are related to the
RequestObject and are shown in Table 1:
Table 1. API ChangesMethodchange
Request (
Item
)In ASP, this method would return a array of strings. In ASP. NET, it returns a
NameValueCollection.
Request.QueryString (
Item
)In ASP, this method would return a array of strings. In ASP. NET, it returns a
NameValueCollection.
Request.Form (
Item
)In ASP, this method would return a array of strings. In ASP. NET, it returns a
NameValueCollection.
As you can, the changes are basically is the same for all methods involved.
If the
ItemYou are are accessing contains exactly one value for the specified key and you don't need to modify code. However, if there are multiple values for a given key, you should need to use a different method to return the collection of Valu Es. Also, note this collections in Visual Basic. NET are zero-based, whereas the collections in VBScript are one-based.
For example, in ASP the individual query string values from a request to http://localhost/myweb/valuetest.asp?values=10&am P;VALUES=20 would be accessed as follows:
<% ' This'll output "ten" Response.Write request.querystring ("Values") (1) ' This'll output ' Response.Write Request.QueryString ("Values") (2)%>
In ASP. NET, the
QueryStringproperty returns a
NameValueCollectionObject from which your need to retrieve the
ValuesCollection before retrieving the actual item you want. Again, note the ' The ' collection is retrieved by using a ' index of zero rather than one:
<% ' This'll output "ten" Response.Write (Request.QueryString.GetValues ("Values") (0)) ' This'll output ' Re Sponse. Write (Request.QueryString.GetValues ("Values") (1))%>
In both the case of ASP and ASP. NET, the follow code would behave identically:
<% ' This'll output "ten", "Response.Write" (Request.QueryString ("values"))%>
Structural Changes
Structural changes are those that affect the layout and coding style of Active Server Pages. You are need to be aware of several of this to ensure your code would work in ASP.
Code blocks:declaring functions and Variables
In ASP, you can declare subroutines and global variables in between your code delimiters.
<% Dim X Dim str Sub mysub () Response.Write "This is a string." End Sub%>
In ASP.. NET, which is no longer allowed. You are must instead declare all of your functions variables and inside a <script> blocks.
<script language = "vb" runat = "server" > Dim str As String Dim x, y As Integer Function Add (I As Integer, J A s integer) As Integer return (I + J) End function</script>
Mixing programming Languages
In ASP, your basically have two choices for your programming language:vbscript or microsoft®jscript®. You are are free to mix and match blocks of script in the same page at'll.
In ASP. NET, you currently have three options. can use C #, Visual Basic. NET, or JScript. Note I said Visual Basic. NET instead of VBScript. This is because VBScript does isn't exist in the. NET platform. It has been fully subsumed by Visual Basic. NET. Although you are free to pick any of the above languages, it is important to this you cannot mix languages on the same PA GE as you could does in ASP. It is certainly possible to have
page1.aspxof your application contain C # code while
page2.aspxOf the same application contains Visual Basic. NET code. You are just cannot mix them together in a single page.
New Page directives
In ASP your must place all directives on the ' the ' a page within the same delimiting block. For example:
<%language= "VBSCRIPT" codepage= "932"%>
In ASP. NET, you are now required the
Languagedirective with a
Pagedirective, as follows:
<% @Page language= "VB" codepage= "932"%><% @QutputCache duration= "None" varybyparam=
can have as many lines of directives as you need. Directives may being located anywhere in your. apsx file but standard practice are to place them at the beginning of the file.
Several new directives have been added in ASP. NET. I encourage to look at the up and down in the ASP. NET documentation to the I/They may benefit your application.
Render functions Are No longer Valid
In ASP, the developers figured out this they could do clever the by using the things is what a "termed Function." A Render Function is basically a subroutine that contains chunks of the HTML embedded throughout its body. For example:
<%sub renderme ()%>
Although can do some cool things using these types the functions, this type of coding is no longer allowed in ASP. This is probably for the better. I am sure you have seen functions then quickly become unreadable and unmanageable when your start to mix and match code and HTML like this. The simplest way to make this work in ASP. NET are to replace your HTML outputs with calls to
Response.Writeas follows:
<script language= "VB" runat= "Server" > Sub renderme () Response.Write ("<H3> This is HTML text being Rende Red. </H3> ") End sub</script><% call Renderme ()%>
Note I said "simplest way." This does isn't necessarily mean it is the best way. Depending on the complexity and amount of your rendering code, it may is beneficial for your look into using custom Web controls, which allow to programmatically set your HTML attributes and truly separate the code from your content. Doing so makes to much more readable code.
Visual Basic Language Changes
As I mentioned earlier, VBScript has been deprecated in favor to the more complete and more powerful visual Basic. NET. In this section, I'll highlight some of the issues you are likely to encounter related to Visual Basic language. It is important to the ' not ' meant to be a exhaustive list of the changes made to Visual Basic. Instead, I have focused on the items so you as a asp/vbscript programmer would likely encounter to ASP. NET using Visual Basic. NET. Consult the Visual Basic. NET documentation for a complete list of all language changes that have been.
Farewell to the Variant Data Type
We know it, we love it and we love to hate it. I am Speaking of a VARIANT data type, of course. Variants are not the. NET and thus are not supported in Visual Basic. Net. What This means was that all of your ASP variables are silently to move from VARIANT going to
ObjectTypes. Most variables used in your application can and should is changed to a corresponding primitive type depending on your need S. If your variable is really
ObjectType in Visual Basic terms, simply explicitly declare it as
ObjectType in ASP. NET.
Visual Basic Date Type
One VARIANT type that warrants some special attention is the
Vt_dateType, which manifests itself in Visual Basic as a
DateType. In Visual Basic, a
Dateis stored in a Double format using four bytes. In Visual Basic. NET,
DateUses the Common Language Runtime
DateTimeType, which has an eight byte integer representation.
Since everything is a VARIANT in ASP, your intended
DateVariables would compile and may continue to work depending in how they are. It is possible, however, which you'll run into some unexpected problems performing certain with the operations B Ecause the underlying type has been changed. Pay attention to areas where you are passing the date value into COM objects as long integer values or performing Certa In casting operations on date types using
CLng.
Option Explicit is now the Default
In ASP, the
Option ExplicitKeywords were available but were not enforced as the default. In Visual Basic. NET, this has changed.
Option Explicitare now the default so all variables need to be declared. It is good practice to being even more rigid than the This and change your setting to
Option Strict. Doing so forces your to declare all of your variables as a specific data type. While this may seem like extra work, it really are the way you should be doing things. If you don't choose to, your code would be less than optimal as all undeclared variables would become
ObjectTypes. Most implicit conversions'll still work, but you'll probably be better off and safer if you explicitly declare all of Your variables to the types your want them to be.
Let and SET Are No longer supported
Objects can be assigned to one another directly like this:myobj1 = MyObj2. You are no longer need to use the
SETOr
LetStatements. If You use this statements, they must be removed.