您现在的位置: 军旅同心-旅游自驾-军旅文学 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 正文
把ASP移植到ASP+
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 13:11:36
;/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 th

上一页  [1] [2] [3] 下一页


更多
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 网站地图 | 版权申明 | 网站公告 | 管理登录 |