Migration of your Classic ASP applications to ASP.NET can be a time consuming
operation due to the fact that .NET application design/architecture is
fundamentally different from Classic ASP, and in most cases it seems to be a
complete rewrite of existing applications.
Classic ASP and ASP.NET are processed by their own respective engines, therefore
to take advantage of new features and to levarge on the faster processing
capabilities of ASP.NET, we can convert our Classic ASP pages to ASP.NET
(Hybrid) pages. I call them Hybrid because in essence these pages are still ASP
but will be processed by ASP.NET Engine.
Following list of 10 will help you achieve this with efficiently and without
spending to much of your time.
| 1 ) |
Add a page level directive at the top of the .aspx page
<%@ Page Language="vb" aspcompat="true">
This directive tells .NET engine to expect use of VB.NET language in the page,
it could very easily be "c#". The second part of this directive
(aspcompat="true"), lets you use Older COM components which use Compartment
Threading. This directive is optional, but as a quick reference, any of your
ASP page which uses ADO is required to have this directive included.
|
| |
| 2 ) |
In classic ASP, most popular way of reusing code is with #includes. They can
stay as is in your .aspx pages. The alternate to that approach is to use User
Controls. During my testing i found same performance results from both
techniques. as an example if you have a common Header for all your .asp pages
the include directive will look like this.
<!--#include virtual="/includes/header.asp"-->
To convert this to use User Controls, rename your Header.asp file to
Header.ascx , and add
<%@ Control Language="vb" %>
at the top of that page, then in your .aspx page add following
<%@ Register TagPrefix="cc" TagName="Header"
Src="/PerfTest/Header.ascx" %>
just after your Page directive and replace your #include statement with the
following
<cc:Header id="Header1" runat="server" ></cc:Header>
|
| |
| 3 ) |
.NET framework now requires you to declare all variables before you use them.
so you have to Dim all your variables. It will be easier if
your .ASP code was written with OPTION EXPLICIT
|
| |
| 4 ) |
Keyword "Set" has been removed from vb language, so the staement
Set oCon=Server.CreateObject("ADODB.Connection")
will have to be re-written as,
oCon=Server.CreateObject("ADODB.Connection")
|
| |
| 5 ) |
All your method calls now have to be in paranthesis () e.g.
Response.Write "Some Text to be written."
should be changed to
Response.Write ("Some Text to be written.")
|
| |
| 6 ) |
The ASP Intrinsic objects namely Server, Request, Response, Application and
Session are still maintained in .NET. You can use them without any change.
|
| |
| 7 ) |
If you have Sub and Functions defined on the
.ASP page using "<%" tag they have to be replaced with <SCRIPT
LANGUAGE="VBScript" runat="server"> e.g.
<%
Function ReturnSomeValue(i)
ReturnSomeValue= i+1
End Function
%>
Should be changed to
<SCRIPT LANGUAGE="VBScript" runat="server">
Function ReturnSomeValue(i)
ReturnSomeValue= i+1
End Function
</SCRIPT>
|
| |
| 8 ) |
The keyword IsNull or Null is no longer part of vb.NET. All comparisons and
checks for "Null" values have to be replaced with System.DBNull.Value, e.g.
if ( isnull(n) ) then ...
Should be changed to
if (n is System.DBNull.Value ) then ...
|
| |
| 9 ) |
.NET framework introduces a concept of Configuration file, namely web.config,
which is an ideal place to store your application level constants like Database
Connection strings, environment vars etc. In order to make use of this very
convenient feature you first have to add web.config file to your Web
Applications root folder. Add the AppSettings Section to this file. Web.Config
file is a XML file, so it can be edited using any text editor.
<appSettings>< br>
<addkey="DBCon"value="server=localhost;Initial
Catalog= Northwind;userid=sa;password=" />
</appSettings>
To read this setting in your .aspx page use,
System.Configuration.ConfigurationSettings.AppSettings("DBCon")
|
| |
| 10 ) |
The absence of Framework provided Application Tracing made Classic ASP
developers make use of Response.Write's. The .NET Framework now provides a very
comprehensive tracing mechanism. to use that add Trace=True attribute
the @Page directive of your page and then use
Trace.Write ("some trace message")
at any place you want. You dont have to delete or comment your Trace statements
when you put your code to Production , simply remove the Trace=True attribute
from @Page directive.
|