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

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


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