Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Update Asp Code to Asp.net Code

0.00/5 (No votes)
7 May 2005 1  
Update classic asp code to aspx

Sample Image - interface.jpg

Introduction

We know Asp.Net does support ADO. But, if we simply change the file's postfix from ".asp" to ".aspx", always those files do not work. However it is not very hard to make them work. We can use some very simply rules to modify those files and make them work again. In this way can protect you company's investment in asp times. When you want to add new web capabilities, you can simply write them as classic Asp.Net Web Form, and don't need any session sharing bridge in the old asp code and the new Asp.Net code.

We make a automatic tool to do those jobs.

How to Update

(1)First change all file postfix in every page, from ".asp",".txt",".inc" to ".aspx". Both in file text itself and file postfix.

(2)Second use the mapping table as below, change Asp code.
ASP ASP.net
set rs=Server.CreateObject("ADODB.RECORDSET") rs=Server.CreateObject("ADODB.RECORDSET")
Rs("ColumnID") Rs.Fields("ColumnID").value
<%=parameter%> <%Response.Write(parameter)%>
If parameter="SET" Then parameter="GET" End If If parameter="SET" Then
    parameter="GET"
End If
IsNull IsDBNull
InEmpty IsNothing
If CDate(****1)-CDate(****2)>0 Then If CDate(****1)>CDate(****2) Then
If session("LoginTime")="" Then
   session("LoginTime")=0
End If
If IsNothing(session("LoginTime")) Then
    session("LoginTime")=""
End If
If session("LoginTime").ToString()="" Then
   session("LoginTime")=0
End If
call CustomerSub("Parameter1") CustomerSub("Parameter1")
CustomerSub "Parameter1" CustomerSub("Parameter1")
While(....)
Wend
While(....)
End While
 

(3)Third Cut all customer define functions or subs to a VB Library project named WebLibrary's class named AspCommonFunction. Make all those functions or subs as  AspCommonFunction's shared function. import library System.Web for this project. Add five basic objects (Server,Application,Session,Request,Response) for each function as parameters. Add import library in every asp page begin place.
<%@ Import Namespace="WebLibrary" %>
Change function in asp page as below.
ASP ASP.net
Function myfunction1()
        myfunction1="Test"
End Function

myfunction1()
In VB library:
Function myfunction1(Server,Application,Session,Request,Response)
       myfunction1="Test"
End Function

In Asp code:
WebLibrary.AspCommonFunction.myfunction1(Server,Application,Session,Request,Response)
Function myfunction2(para1)
      myfunction2=para1
End Function

str=myfunction2("Test 2")
In VB library:
Function myfunction2(para1,Server,Application,Session,Request,Response)
      myfunction2=para1
End Function

In Asp code:
WebLibrary.AspCommonFunction.myfunction2("Test 2",Server,Application,Session,Request,Response)

Add parameter for some functions that need more shared parameters.
ASP ASP.net
Function myfunction3(para1)
      myfunction2=commonString+para1
End Function

str=myfunction2("Test 2")
In VB library:
Function myfunction2(para1,Server,Application,Session,Request,Response,commonString)
      myfunction2=commonString+para1
End Function

In Asp code:
WebLibrary.AspCommonFunction.myfunction2("Test 2",Server,Application,Session,Request,Response,commonString)

Date function in asp code is used as getting current date. It does not supported in Asp.net yet. So we define a new function named GetCurrentDate() to replace this function.

(4)We may define same customer function name in different asp files. So when we cut those codes from asp file to VB library, we should change the repeated function name to another name.

(5)In the end of each page that has included other pages, add this sentence
<% @Page Language="VB" Explicit="False" aspcompat="True"%>
To announce that this aspx page do not need Explicit parameters and can use asp Components.

Automatic Tools Introduce

(1)This tool can automatically change code from classic asp to aspx, and cut customer functions and subs to a VB Library. It also can deal with the Repeat Name in library.


(2)It also support a tool for manually add parameters for functions. It will according the "include" target in asp files to update all the text that use this function.
 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here