65.9K
CodeProject 正在变化。 阅读更多。
Home

将 Asp 代码更新为 Asp.net 代码

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.83/5 (7投票s)

2005年5月8日

3分钟阅读

viewsIcon

51735

downloadIcon

784

将经典 asp 代码更新为 aspx。

Sample Image - interface.jpg

引言

我们知道 Asp.Net 支持 ADO。不过,如果我们只是将文件的后缀从 ".asp" 改为 ".aspx",这些文件通常无法工作。然而,要让它们工作起来并不难。我们可以使用一些非常简单的规则来修改这些文件,使它们能够再次工作。这样可以保护您的公司在 Asp 时期的投资。当您想要添加新的 Web 功能时,您可以将它们写成经典的 Asp.Net Web Form,而无需在旧的 asp 代码和新的 Asp.Net 代码之间设置任何会话共享桥接。

我们制作了一个自动工具来完成这些工作。

如何更新

(1)首先,将每个页面中的所有文件后缀从 ".asp"、".txt"、".inc" 改为 ".aspx"。包括在文件文本本身和文件后缀中。

(2)其次,使用下面的映射表,修改 Asp 代码。
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)第三,将所有自定义的函数或子过程剪切到一个名为 WebLibrary 的 VB 库项目中,其类名为 AspCommonFunction。将所有这些函数或子过程设为 AspCommonFunction 的共享函数。为此项目导入 System.Web 库。为每个函数添加五个基本对象(Server、Application、Session、Request、Response)作为参数。在每个 asp 页面的开头添加导入库。
<%@ Import Namespace="WebLibrary" %>
如下更改 asp 页中的函数。
ASP ASP.net
Function myfunction1()
        myfunction1="Test"
End Function

myfunction1()
在 VB 库中:
Function myfunction1(Server,Application,Session,Request,Response)
       myfunction1="Test"
End Function

在 Asp 代码中:
WebLibrary.AspCommonFunction.myfunction1(Server,Application,Session,Request,Response)
Function myfunction2(para1)
      myfunction2=para1
End Function

str=myfunction2("Test 2")
在 VB 库中:
Function myfunction2(para1,Server,Application,Session,Request,Response)
      myfunction2=para1
End Function

在 Asp 代码中:
WebLibrary.AspCommonFunction.myfunction2("Test 2",Server,Application,Session,Request,Response)

为需要更多共享参数的函数添加参数。
ASP ASP.net
Function myfunction3(para1)
      myfunction2=commonString+para1
End Function

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

在 Asp 代码中:
WebLibrary.AspCommonFunction.myfunction2("Test 2",Server,Application,Session,Request,Response,commonString)

Asp 代码中的 Date 函数用于获取当前日期。它尚未在 Asp.net 中得到支持。因此,我们定义了一个名为 GetCurrentDate() 的新函数来替换此函数。

(4)我们可能会在不同的 asp 文件中定义相同的客户函数名。因此,当我们将这些代码从 asp 文件剪切到 VB 库时,我们应该将重复的函数名更改为另一个名称。

(5)在包含其他页面的每个页面末尾,添加此语句
<% @Page Language="VB" Explicit="False" aspcompat="True"%>
以声明此 aspx 页面不需要 Explicit 参数,并且可以使用 asp 组件。

自动工具介绍

(1)此工具可以自动将经典 asp 代码转换为 aspx,并将自定义函数和子过程剪切到 VB 库。它还可以处理库中的重复名称。


(2)它还支持一个手动添加函数参数的工具。它将根据 asp 文件中的 "include" 目标来更新使用此函数的所有文本。
 

© . All rights reserved.