开店乐

开店乐电子商务研究 KaiDianLe.Com

网站地图 :

  搜索:

把ASP移植到ASP+

Before embarking on the inevitable—and not painless—migration to ASP+, it's best to know what
compatibility issues you'll have to deal with

by Chris Kinsman


  Microsoft is set to release an exciting upgrade to ASP later in 2000. This is a major upgrade unlike the
minor changes from ASP 2.0 to 3.0. Unlike past upgrades, however, this one will not be painless. When they
designed ASP+, Microsoft had to make the hard decision occasionally to break backward compatibility in the
interest of improved functionality and features.
What you need:

ASP+ PDC Preview




At the Professional Developer Conference 2000 ASP+ Development Lead Scott Guthrie mentioned that Microsoft
was guided by the idea that "There is more Internet time ahead of us than behind us." As an ASP developer
with hundreds of thousands of lines of code directly affected by this, I am worried. At the same time, I
sincerely feel that they made the right decision.

Compatibility Issues
What does Microsoft's decision about selective backwards-compatibility mean for you? At the most basic it
means that migrating will require work. All but the most simple pages will likely require changes before
they will run correctly under ASP+. Microsoft has made available a migration path from ASP to ASP+. Both
ASP and ASP+ will run side by side on the same server without interacting. This means that your ASP
applications will continue to run—albeit without taking advantage of new ASP+ functionality—while you
are developing your new ASP+ pages. No modifications have been made to asp.dll, and nothing should break
by installing ASP+.

This side-by-side operability is accomplished by using separate filename extensions for ASP and ASP+. All
ASP+ filename extensions that I have seen so far end in an x (for example, .aspx, .asmx, etc.). The only
exception would be new pagelets (miniature ASP+ pages—more about them later) that use the .aspc
extension. This means that migration will typically entail copying an .asp file to an .aspx file, testing
it, fixing the problems, and then deploying it by relinking the rest of the site to the file with the new
extension.

Microsoft has mentioned that by the time the product ships they hope to have a conversion tool ready which
will point out incompatibilities and, in some instances, fix them for you. This won't fix all
incompatibilities but it will cover the majority. Compatibility issues come in three broad categories: API
changes, semantic changes, and language changes.

API Changes: The first set of compatibility issues arise around changes to the core ASP objects. All of
the arrays are now 0 index based. In the previous versions some arrays were 1 based and others were 0
based. For consistency, all now use a 0 base.

The second change has to do with the return types of certain objects. In ASP, Request,
Request.QueryString, and Request.Form return different results based on what is in them. If I access a
page with the following Url—http://localhost/apichanges.asp?Language=VB&Language=C#—and it contains the
following code:

<%
    ' Writes out: VB, C#
    Response.Write Request.QueryString("Language")

    ' Writes out: VB
    Response.Write Request.QueryString("Language")(1)
%>
then depending on the way I invoke Request.QueryString, I will get differing results. One would have
thought that the first invocation would return a string array, as opposed to a CSV string. ASP+ has
changed this model. Now to get the individual items you must call an explicit method to get access to the
items. Using the same URL as above, the following ASP+ code will provide the same functionality:
<%
    ' Writes out: VB, C#
    Response.Write(Request.QueryString("Language"))

    ' Writes out: VB
    Response.Write(Request.QueryString.GetValues("Language")(0))
%>
The most common places you are going to find code like the preceding—which requires updating—is in
places where you have multiple select listboxes, multiple radio buttons or checkboxes with the same name,
and multiple submit buttons.
There isn't really much that you can do when writing code to prepare for this change except potentially
wrap control access with your own subroutines so that you can centralize the fixes for the API change.

Although changes in the intrinsic objects are easily fixed in ASP pages using script code, what about
compiled COM components for which you don't have the source? As it turns out, if your COM components use
GetObjectContext to gain access to the intrinsic ASP objects, ASP+ will return to them a copy of the
intrinsic ASP objects compatible with ASP. This support is not in the PDC build of ASP+ but will be
forthcoming in future builds. That being said, using compiled Visual Basic 6 objects yields a performance
penalty in ASP+ of 10 to 15 percent. This is due to the increased cost of marshalling data between managed
and unmanaged code as well as threading issues due to ASP+ switching to an MTA thread pool. For the long
term this means that you are going to want to rewrite your components using managed code.


--------------------------------------------------------------------------------------------------------

ASP to ASP+ Migration (cont'd)



  Semantic Changes: ASP+ also introduces several changes to the basic semantics of the page. From a
compatibility and migration standpoint, the most important ones boil down to three:
Only one language per page

Functions must be in script blocks

Render functions are not supported
ASP allowed you to mix more than one scripting language per page. You could write one function in
javascript, another in VBScript, and use them interchangeably on the same page. ASP+ has eliminated this
capability. In ASP+ only one language is allowed per page. This doesn't mean you can't have client-side
javascript and server-side Visual Basic in the same page. If you really must mix server-side languages in
a single page, check out the new pagelets capability. Pagelets are miniature ASP+ pages that can be
embedded in other pages. This allows you to use javascript in a pagelet and Visual Basic in the page that
embeds it. The main reason for this change is the move from scripted languages to compiled languages. With
a common scripting engine runtime it was relatively easy for multiple interpreted scripting languages to
share the same symbol table and coexist on a page. With ASP+ all code is compiled into a class that
represents the page. Two different languages would require two different compiles with two different
outputs and two different symbol tables.
In addition, functions must be placed inside of script blocks. I suspect this is also due to the move from
scripting languages to compiled languages, but I don't know the exact technical reasons. What it means to
developers is that instead of:

<%
     Function MyFunc()


     End Function
%>
you must now write like this:
<SCRIPT LANGUAGE="VB" runat=server>
    Function MyFunc()

    End Function
</SCRIPT>
This isn't a big deal, but it's a change that you must make nonetheless.
Tip: Start placing your functions and subroutines into script blocks today to make the migration easier
later on.

Render functions are really a specialized form of the fact that functions must be declared in script
blocks. As a side-effect of the way scripting was implemented, it was possible to write functions like
this:

<%
     Function DrawTable()
%>
          <table>
               <tr>
                    <td>
<%
                         Response.Write "Hello World"
%>
                    </td>
               </tr>
          </table>
<%
     End Function
%>
This code fragment uses the ASP <% %> escaping syntax to drop from code back to raw HTML. ASP treats these
chunks of HTML as though they had been emitted using Response.Write and inserts them into the calling
page. Now that functions must be enclosed in script blocks there isn't an easy way to do escape embedded
HTML and the above must be changed to look like this:
<SCRIPT LANGUAGE="VB" runat=server>
     Function DrawTable()
          Response.Write "<table><tr><td>"
          Response.Write "Hello World"
          Response.Write "</td></tr></table>"
     End Function
</SCRIPT>
VB Language Changes: The final category of compatibility issues doesn't really deal with ASP itself but
with the languages it uses. ASP+ no longer uses scripting languages. If you previously used VBScript, all
that code will be executed using the Visual Basic compiler. Visual Basic itself has had several
significant changes in this revision and therefore creates additional compatibility issues. There are four
known issues at this point, although additional ones may crop up as Visual Basic continues to change
during development:
Visual Basic no longer has default properties. You must now fully qualify all non-indexed properties to
identify which property you want. Instead of writing "rsData("Name")" you must write "rsData
("Name").Value."
Tip: Prepare for this now by always explicitly specifying the property you want and not relying on the
default property.

Visual Basic no longer has both a set and a let. Set was originally introduced in Visual Basic 4 to
differentiate between value assignments and object assignments. Some objects in Visual Basic 4 would
return either an object or a string. The ActiveConnection property of an ADO command object is an example
of this. Because of this dual nature, Set was needed to indicate an object assignment and Let was used to
indicate the string assignment. With the elimination of default properties, however, this is no longer an
issue. Instead of writing:
Set cn = Server.CreateObject("ADODB.Connection")
you can now write:
cn = Server.CreateObject("ADODB.Connection")


Visual Basic now requires parentheses around all subroutine calls. In previous versions of Visual Basic
they could be used with a single argument but could not be used with more than one argument unless you
used the Call keyword. In my code this is going to be the one that requires the most cleanup. The common
case will be the use of Response.Write. Where I previously used it like this:
Response.Write "Test: " & iCount
it will now have to be called like this:
Response.Write("Test: " & iCount)


The way arguments are passed to subroutines and functions has changed from VBScript to Visual Basic. In
VBScript arguments were passed ByRef by default. With Visual Basic arguments are passed ByVal by default.
Tip: If you rely on the passing of arguments ByRef, explicitly include the keyword in your code to make
your code more portable to ASP+.
Performance Considerations
Although this is not strictly a migration issue, ASP+ developers will see significant performance
increases when porting their ASP code if they move all of their variable instances from loosely typed
variants to strongly typed data types. This one change alone can yield significant performance increases.
Additionally, rewriting existing COM components as managed code will eliminate many performance penalties
due to marshalling and threading.
In summary, ASP+ offers some very cool new features but they aren't entirely free. Migrating from ASP to
ASP+ will require some work. However, careful attention to the aforementioned issues today will mean that
your code ports much easier once ASP+ ships.


Chris Kinsman is Vice President of Technology at DevX.com. He is reponsible for the site architecture,
development, and day-to-day maintenance of the DevX network of sites.


ASP to ASP+ Migration (cont'd)



  Semantic Changes: ASP+ also introduces several changes to the basic semantics of the page. From a
compatibility and migration standpoint, the most important ones boil down to three:
Only one language per page

Functions must be in script blocks

Render functions are not supported
ASP allowed you to mix more than one scripting language per page. You could write one function in
javascript, another in VBScript, and use them interchangeably on the same page. ASP+ has eliminated this
capability. In ASP+ only one language is allowed per page. This doesn't mean you can't have client-side
javascript and server-side Visual Basic in the same page. If you really must mix server-side languages in
a single page, check out the new pagelets capability. Pagelets are miniature ASP+ pages that can be
embedded in other pages. This allows you to use javascript in a pagelet and Visual Basic in the page that
embeds it. The main reason for this change is the move from scripted languages to compiled languages. With
a common scripting engine runtime it was relatively easy for multiple interpreted scripting languages to
share the same symbol table and coexist on a page. With ASP+ all code is compiled into a class that
represents the page. Two different languages would require two different compiles with two different
outputs and two different symbol tables.
In addition, functions must be placed inside of script blocks. I suspect this is also due to the move from
scripting languages to compiled languages, but I don't know the exact technical reasons. What it means to
developers is that instead of:

<%
     Function MyFunc()


     End Function
%>
you must now write like this:
<SCRIPT LANGUAGE="VB" runat=server>
    Function MyFunc()

    End Function
</SCRIPT>
This isn't a big deal, but it's a change that you must make nonetheless.
Tip: Start placing your functions and subroutines into script blocks today to make the migration easier
later on.

Render functions are really a specialized form of the fact that functions must be declared in script
blocks. As a side-effect of the way scripting was implemented, it was possible to write functions like
this:

<%
     Function DrawTable()
%>
          <table>
               <tr>
                    <td>
<%
                         Response.Write "Hello World"
%>
                    </td>
               </tr>
          </table>
<%
     End Function
%>
This code fragment uses the ASP <% %> escaping syntax to drop from code back to raw HTML. ASP treats these
chunks of HTML as though they had been emitted using Response.Write and inserts them into the calling
page. Now that functions must be enclosed in script blocks there isn't an easy way to do escape embedded
HTML and the above must be changed to look like this:
<SCRIPT LANGUAGE="VB" runat=server>
     Function DrawTable()
          Response.Write "<table><tr><td>"
          Response.Write "Hello World"
          Response.Write "</td></tr></table>"
     End Function
</SCRIPT>
VB Language Changes: The final category of compatibility issues doesn't really deal with ASP itself but
with the languages it uses. ASP+ no longer uses scripting languages. If you previously used VBScript, all
that code will be executed using the Visual Basic compiler. Visual Basic itself has had several
significant changes in this revision and therefore creates additional compatibility issues. There are four
known issues at this point, although additional ones may crop up as Visual Basic continues to change
during development:
Visual Basic no longer has default properties. You must now fully qualify all non-indexed properties to
identify which property you want. Instead of writing "rsData("Name")" you must write "rsData
("Name").Value."
Tip: Prepare for this now by always explicitly specifying the property you want and not relying on the
default property.

Visual Basic no longer has both a set and a let. Set was originally introduced in Visual Basic 4 to
differentiate between value assignments and object assignments. Some objects in Visual Basic 4 would
return either an object or a string. The ActiveConnection property of an ADO command object is an example
of this. Because of this dual nature, Set was needed to indicate an object assignment and Let was used to
indicate the string assignment. With the elimination of default properties, however, this is no longer an
issue. Instead of writing:
Set cn = Server.CreateObject("ADODB.Connection")
you can now write:
cn = Server.CreateObject("ADODB.Connection")


Visual Basic now requires parentheses around all subroutine calls. In previous versions of Visual Basic
they could be used with a single argument but could not be used with more than one argument unless you
used the Call keyword. In my code this is going to be the one that requires the most cleanup. The common
case will be the use of Response.Write. Where I previously used it like this:
Response.Write "Test: " & iCount
it will now have to be called like this:
Response.Write("Test: " & iCount)


The way arguments are passed to subroutines and functions has changed from VBScript to Visual Basic. In
VBScript arguments were passed ByRef by default. With Visual Basic arguments are passed ByVal by default.
Tip: If you rely on the passing of arguments ByRef, explicitly include the keyword in your code to make
your code more portable to ASP+.
Performance Considerations
Although this is not strictly a migration issue, ASP+ developers will see significant performance
increases when porting their ASP code if they move all of their variable instances from loosely typed
variants to strongly typed data types. This one change alone can yield significant performance increases.
Additionally, rewriting existing COM components as managed code will eliminate many performance penalties
due to marshalling and threading.
In summary, ASP+ offers some very cool new features but they aren't entirely free. Migrating from ASP to
ASP+ will require some work. However, careful attention to the aforementioned issues today will mean that
your code ports much easier once ASP+ ships.


Chris Kinsman is Vice President of Technology at DevX.com. He is reponsible for the site architecture,
development, and day-to-day maintenance of the DevX network of sites.

【日期:2006-8-5】【作者:不祥】【转载自:开店乐】

相关文章:
 最好的网上开店系统:凡人网络购物系统免费下载
 Rs.open sql,conn,A,B 的A、B各代表什么?
 ASP开发中存储过程应用全接触
 Oracle大文本在ASP中存取问题的解决
 数据分页方法新思路,速度非常快!
 ASP+vbscript写的万能查询表达式生成器
 常用网站数据库SQL操作语句
 ASP程序与SQL存储过程详解
 ASP脚本一空间绑定多个域名代码
 WEB编程开发常用的代码大全
 解决大字段在Form中Post出错的方法
 学习ASP之编写安全的ASP代码
 ASP程序应用之模板采用
 防止别人批量采集功能的ASP代码
 网页图片下拉选择控件使用实例
 平时写程序的时候出错时的解决方法
 “在线访客”的制作方法
 ASP中数据库调用时常见错误的现象和解决
 ASP 编程中20个非常有用的例子
 经典实用的基础asp程序整理
 ASP中从数据库读取二进制文件数据代码
 ASP动态生成的javascript表单验证代码
 在电子商务中实现购物车的方法
 ASP利用Google实现在线翻译功能
 实现千万级数据分页的存储过程
 详细说明用ASP和WML来实现数据库查询
 ASP访问INTERBASE数据库
 ASP安全配置不完全手册
 在ASP中如何访问Novell下的数据库
 ASP进阶学习必经之认识数学函数11种
 初学者必读 ASP运行环境的搭建
 解析asp的脚本语言
 学习使用ASP对象和组件
 让ASP程序运行于非Windows平台
 通过启动脚本来感受ASP的力量
 一些不长见的ASP调用存储过程的技巧
 使用ASP脚本技术
 优化Web数据库页面
 Asp限制IP访问代码
 ACCESS数据库防下载另类方法
 ASP浏览器性能组件
 细说ASP中Counters 组件
 全面解析Server对象
 ASP 内建对象Request和Respones
 深入研究Application和Session对象
 使用ASP、VB和XML建立运行于互联网上的应用程序
 在客户端执行数据库记录的分页显示
 对ASP脚本源代码进行加密
 用代码打开Access文件的两种方法
 使用Visual InterDev进行小组开发
 用JScript脚本实现分页的另类办法
 ASP中Cookie读写的实现方法
 如何使用ASP建立虚拟的FTP服务器
 在ASP中自动创建多级文件夹的函数
 一个硬盘文件搜索的Asp源码
 ASP使用MYSQL数据库全攻略
 ASP上传数据流格式分析详解
 ASP汉字转换UTF-8及UTF-8转换GB2312
 ASP常用数据库连接及操作的方法
 ASP编程中常用SQL命令使用方法
 ASP查询记录时RecordCount=-1问题
 让你的WAP网站有更好的兼容性
 如何注册服务器端组件
 轻松实现任何程序和动易整合
 在服务器端调用winzip命令行对上传的多个文件打包压缩
 用ASP制作强大的搜索引擎
 ASP彩色校验码的制作
 ASP 系列函数大全
 ASP程序处理进程进度条
 Asp无组件生成缩略图
 用ASP实现自动建站.实现虚拟二级目录
 删除Access数词库中的空记录
 ASP身份证验证代码函数
 ASP写的自动生成SELECT表单的函数
 几种打开记录集方式的比较
 用ASP实现汉字转拼音的功能
 ASP分页代码,已经写成类了,值得参考
 ASP下载系统防盗链方法
 Global.asa文件用法大全
 如何防止页面中的敏感信息被提取
 Delphi编写组件封装asp代码的基本步骤
 制做行背景颜色交替变换的表格
 如何用foreach遍历页面上所有的TextBox
 将数据库中的信息存储至XML文件中
 用Asp写个加密和解密的类
 如何固定表格的标题行和标题列
 ASP小偷(远程数据获取)程序入门教程
 Asp编写不再让人讨厌的自动弹出窗口
 用ASP实现在线压缩与解压缩
 使用组件封装ASP的数据库操作
 ASP中读写注册表
 ASP判断函数一览及网页制作常用技术
 ASP中Cookie使用指南
 随机产生用户密码(good)
 ASP:如何对身份证的籍贯进行验证
 ASP产生随机密码的函数
 ASP+ADO实现数据读写简单示例
 一个简单的用户登录接口ASP实现
 ASP+SQL Server构建网页防火墙
 一个通用的保护ASP系统的方法
 利用ASP发送和接收XML数据的处理方法

版权所有:Kaidianle.Com  联系方式:Shnxn@Yhaoo.Com.Cn 京ICP备06028743号 在线留言