把ASP移植到ASP+

来源:互联网 发布:上古世纪捏脸兽灵数据 编辑:程序博客网 时间:2024/05/02 14:21

<a href='http://www.biancheng88.cn/html/2008-11/ASP-67111021.html'>把ASP移植到ASP+</a><br><br>
                  Before embarking on the inevitable—and not painless—migration to ASP+, it's best to know what <br>
compatibility issues you'll have to deal with <br>
<br>
by Chris Kinsman <br>
<br>
<br>
  Microsoft is set to release an exciting upgrade to ASP later in 2000. This is a major upgrade unlike the <br>
minor changes from ASP 2.0 to 3.0. Unlike past upgrades, however, this one will not be painless. When they <br>
designed <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a>+, Microsoft had to make the hard decision occasionally to break backward compatibility in the <br>
interest of improved functionality and features. <br>
What you need: <br>
<br>
ASP+ PDC Preview<br>
<br>
<br>
<br>
<br>
At the Professional Developer Conference 2000 ASP+ Development Lead Scott Guthrie mentioned that Microsoft <br>
was guided by the idea that "There is more Internet time ahead of us than behind us." As an ASP developer <br>
with hundreds of thousands of lines of code directly affected by this, I am worried. At the same time, I <br>
sincerely feel that they made the right decision. <br>
<br>
Compatibility Issues<br>
What does Microsoft's decision about selective backwards-compatibility mean for you? At the most basic it <br>
means that migrating will require work. All but the most simple pages will likely require changes before <br>
they will run correctly under ASP+. Microsoft has made available a migration path from ASP to <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a>+. Both <br>
<a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a> and <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a>+ will run side by side on the same server without interacting. This means that your ASP <br>
applications will continue to run—albeit without taking advantage of new ASP+ functionality—while you <br>
are developing your new ASP+ pages. No modifications have been made to asp.dll, and nothing should break <br>
by installing ASP+. <br>
<br>
This side-by-side operability is accomplished by using separate filename extensions for ASP and <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a>+. All <br>
ASP+ filename extensions that I have seen so far end in an x (for example, .aspx, .asmx, etc.). The only <br>
exception would be new pagelets (miniature <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a>+ pages—more about them later) that use the .aspc <br>
extension. This means that migration will typically entail copying an .asp file to an .aspx file, testing <br>
it, fixing the problems, and then deploying it by relinking the rest of the site to the file with the new <br>
extension. <br>
<br>
Microsoft has mentioned that by the time the product ships they hope to have a conversion tool ready which <br>
will point out incompatibilities and, in some instances, fix them for you. This won't fix all <br>
incompatibilities but it will cover the majority. Compatibility issues come in three broad categories: API <br>
changes, semantic changes, and language changes. <br>
<br>
API Changes: The first set of compatibility issues arise around changes to the core ASP objects. All of <br>
the arrays are now 0 index based. In the previous versions some arrays were 1 based and others were 0 <br>
based. For consistency, all now use a 0 base. <br>
<br>
The second change has to do with the return types of certain objects. In ASP, Request, <br>
Request.QueryString, and Request.Form return different results based on what is in them. If I access a <br>
page with the following Url—http://localhost/apichanges.asp?Language=VB&Language=C#—and it contains the <br>
following code: <br>
<br>
<%<br>
    ' Writes out: VB, C#<br>
    Response.Write Request.QueryString("Language")<br>
<br>
    ' Writes out: VB<br>
    Response.Write Request.QueryString("Language")(1)<br>
%><br>
then depending on the way I invoke Request.QueryString, I will get differing results. One would have <br>
thought that the first invocation would return a string array, as opposed to a CSV string. <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a>+ has <br>
changed this model. Now to get the individual items you must call an explicit method to get access to the <br>
items. Using the same URL as above, the following ASP+ code will provide the same functionality: <br>
<%<br>
    ' Writes out: VB, C#<br>
    Response.Write(Request.QueryString("Language"))<br>
<br>
    ' Writes out: VB<br>
    Response.Write(Request.QueryString.GetValues("Language")(0))<br>
%><br>
The most common places you are going to find code like the preceding—which requires updating—is in <br>
places where you have multiple select listboxes, multiple radio buttons or checkboxes with the same name, <br>
and multiple submit buttons. <br>
There isn't really much that you can do when writing code to prepare for this change except potentially <br>
wrap control access with your own subroutines so that you can centralize the fixes for the API change. <br>
<br>
Although changes in the intrinsic objects are easily fixed in ASP pages using script code, what about <br>
compiled COM components for which you don't have the source? As it turns out, if your COM components use <br>
GetObjectContext to gain access to the intrinsic ASP objects, ASP+ will return to them a copy of the <br>
intrinsic ASP objects compatible with ASP. This support is not in the PDC build of <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a>+ but will be <br>
forthcoming in future builds. That being said, using compiled Visual Basic 6 objects yields a performance <br>
penalty in ASP+ of 10 to 15 percent. This is due to the increased cost of marshalling data between managed <br>
and unmanaged code as well as threading issues due to ASP+ switching to an MTA thread pool. For the long <br>
term this means that you are going to want to rewrite your components using managed code. <br>
<br>
<br>
--------------------------------------------------------------------------------------------------------<br>
<br>
ASP to <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a>+ Migration (cont'd) <br>
<br>
<br>
<br>
  Semantic Changes: ASP+ also introduces several changes to the basic semantics of the page. From a <br>
compatibility and migration standpoint, the most important ones boil down to three: <br>
Only one language per page<br>
<br>
Functions must be in script blocks<br>
<br>
Render functions are not supported <br>
<a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a> allowed you to mix more than one scripting language per page. You could write one function in <br>
JavaScript, another in VBScript, and use them interchangeably on the same page. ASP+ has eliminated this <br>
capability. In ASP+ only one language is allowed per page. This doesn't mean you can't have client-side <br>
JavaScript and server-side Visual Basic in the same page. If you really must mix server-side languages in <br>
a single page, check out the new pagelets capability. Pagelets are miniature ASP+ pages that can be <br>
embedded in other pages. This allows you to use JavaScript in a pagelet and Visual Basic in the page that <br>
embeds it. The main reason for this change is the move from scripted languages to compiled languages. With <br>
a common scripting engine runtime it was relatively easy for multiple interpreted scripting languages to <br>
share the same symbol table and coexist on a page. With <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a>+ all code is compiled into a class that <br>
represents the page. Two different languages would require two different compiles with two different <br>
outputs and two different symbol tables. <br>
In addition, functions must be placed inside of script blocks. I suspect this is also due to the move from <br>
scripting languages to compiled languages, but I don't know the exact technical reasons. What it means to <br>
developers is that instead of: <br>
<br>
<%<br>
     Function MyFunc()<br>
<br>
<br>
     End Function<br>
%><br>
you must now write like this: <br>
<SCRIPT LANGUAGE="VB" runat=server><br>
    Function MyFunc()<br>
<br>
    End Function<br>
</SCRIPT><br>
This isn't a big deal, but it's a change that you must make nonetheless. <br>
Tip: Start placing your functions and subroutines into script blocks today to make the migration easier <br>
later on. <br>
<br>
Render functions are really a specialized form of the fact that functions must be declared in script <br>
blocks. As a side-effect of the way scripting was implemented, it was possible to write functions like <br>
this: <br>
<br>
<%<br>
     Function DrawTable()<br>
%><br>
          <table><br>
               <tr><br>
                    <td><br>
<%<br>
                         Response.Write "Hello World"<br>
%><br>
                    </td><br>
               </tr><br>
          </table><br>
<%<br>
     End Function<br>
%><br>
This code fragment uses the ASP <% %> escaping syntax to drop from code back to raw HTML. ASP treats these <br>
chunks of HTML as though they had been emitted using Response.Write and inserts them into the calling <br>
page. Now that functions must be enclosed in script blocks there isn't an easy way to do escape embedded <br>
HTML and the above must be changed to look like this: <br>
<SCRIPT LANGUAGE="VB" runat=server><br>
     Function DrawTable()<br>
          Response.Write "<table><tr><td>"<br>
          Response.Write "Hello World"<br>
          Response.Write "</td></tr></table>"<br>
     End Function<br>
</SCRIPT><br>
VB Language Changes: The final category of compatibility issues doesn't really deal with <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a> itself but <br>
with the languages it uses. ASP+ no longer uses scripting languages. If you previously used VBScript, all <br>
that code will be executed using the Visual Basic compiler. Visual Basic itself has had several <br>
significant changes in this revision and therefore creates additional compatibility issues. There are four <br>
known issues at this point, although additional ones may crop up as Visual Basic continues to change <br>
during development: <br>
Visual Basic no longer has default properties. You must now fully qualify all non-indexed properties to <br>
identify which property you want. Instead of writing "rsData("Name")" you must write "rsData<br>
("Name").Value." <br>
Tip: Prepare for this now by always explicitly specifying the property you want and not relying on the <br>
default property.<br>
<br>
Visual Basic no longer has both a set and a let. Set was originally introduced in Visual Basic 4 to <br>
differentiate between value assignments and object assignments. Some objects in Visual Basic 4 would <br>
return either an object or a string. The ActiveConnection property of an ADO command object is an example <br>
of this. Because of this dual nature, Set was needed to indicate an object assignment and Let was used to <br>
indicate the string assignment. With the elimination of default properties, however, this is no longer an <br>
issue. Instead of writing: <br>
Set cn = Server.CreateObject("ADODB.Connection")<br>
you can now write: <br>
cn = Server.CreateObject("ADODB.Connection")<br>
<br>
<br>
Visual Basic now requires parentheses around all subroutine calls. In previous versions of Visual Basic <br>
they could be used with a single argument but could not be used with more than one argument unless you <br>
used the Call keyword. In my code this is going to be the one that requires the most cleanup. The common <br>
case will be the use of Response.Write. Where I previously used it like this: <br>
Response.Write "Test: " & iCount<br>
it will now have to be called like this: <br>
Response.Write("Test: " & iCount)<br>
<br>
<br>
The way arguments are passed to subroutines and functions has changed from VBScript to Visual Basic. In <br>
VBScript arguments were passed ByRef by default. With Visual Basic arguments are passed ByVal by default. <br>
Tip: If you rely on the passing of arguments ByRef, explicitly include the keyword in your code to make <br>
your code more portable to <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a>+. <br>
Performance Considerations<br>
Although this is not strictly a migration issue, ASP+ developers will see significant performance <br>
increases when porting their ASP code if they move all of their variable instances from loosely typed <br>
variants to strongly typed data types. This one change alone can yield significant performance increases. <br>
Additionally, rewriting existing COM components as managed code will eliminate many performance penalties <br>
due to marshalling and threading. <br>
In summary, ASP+ offers some very cool new features but they aren't entirely free. Migrating from ASP to <br>
ASP+ will require some work. However, careful attention to the aforementioned issues today will mean that <br>
your code ports much easier once <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a>+ ships. <br>
<br>
<br>
Chris Kinsman is Vice President of Technology at DevX.com. He is reponsible for the site architecture, <br>
development, and day-to-day maintenance of the DevX network of sites. <br>
<br>
<br>
ASP to ASP+ Migration (cont'd) <br>
<br>
<br>
<br>
  Semantic Changes: <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a>+ also introduces several changes to the basic semantics of the page. From a <br>
compatibility and migration standpoint, the most important ones boil down to three: <br>
Only one language per page<br>
<br>
Functions must be in script blocks<br>
<br>
Render functions are not supported <br>
ASP allowed you to mix more than one scripting language per page. You could write one function in <br>
JavaScript, another in VBScript, and use them interchangeably on the same page. <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a>+ has eliminated this <br>
capability. In <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a>+ only one language is allowed per page. This doesn't mean you can't have client-side <br>
JavaScript and server-side Visual Basic in the same page. If you really must mix server-side languages in <br>
a single page, check out the new pagelets capability. Pagelets are miniature ASP+ pages that can be <br>
embedded in other pages. This allows you to use JavaScript in a pagelet and Visual Basic in the page that <br>
embeds it. The main reason for this change is the move from scripted languages to compiled languages. With <br>
a common scripting engine runtime it was relatively easy for multiple interpreted scripting languages to <br>
share the same symbol table and coexist on a page. With ASP+ all code is compiled into a class that <br>
represents the page. Two different languages would require two different compiles with two different <br>
outputs and two different symbol tables. <br>
In addition, functions must be placed inside of script blocks. I suspect this is also due to the move from <br>
scripting languages to compiled languages, but I don't know the exact technical reasons. What it means to <br>
developers is that instead of: <br>
<br>
<%<br>
     Function MyFunc()<br>
<br>
<br>
     End Function<br>
%><br>
you must now write like this: <br>
<SCRIPT LANGUAGE="VB" runat=server><br>
    Function MyFunc()<br>
<br>
    End Function<br>
</SCRIPT><br>
This isn't a big deal, but it's a change that you must make nonetheless. <br>
Tip: Start placing your functions and subroutines into script blocks today to make the migration easier <br>
later on. <br>
<br>
Render functions are really a specialized form of the fact that functions must be declared in script <br>
blocks. As a side-effect of the way scripting was implemented, it was possible to write functions like <br>
this: <br>
<br>
<%<br>
     Function DrawTable()<br>
%><br>
          <table><br>
               <tr><br>
                    <td><br>
<%<br>
                         Response.Write "Hello World"<br>
%><br>
                    </td><br>
               </tr><br>
          </table><br>
<%<br>
     End Function<br>
%><br>
This code fragment uses the <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a> <% %> escaping syntax to drop from code back to raw HTML. <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a> treats these <br>
chunks of HTML as though they had been emitted using Response.Write and inserts them into the calling <br>
page. Now that functions must be enclosed in script blocks there isn't an easy way to do escape embedded <br>
HTML and the above must be changed to look like this: <br>
<SCRIPT LANGUAGE="VB" runat=server><br>
     Function DrawTable()<br>
          Response.Write "<table><tr><td>"<br>
          Response.Write "Hello World"<br>
          Response.Write "</td></tr></table>"<br>
     End Function<br>
</SCRIPT><br>
VB Language Changes: The final category of compatibility issues doesn't really deal with ASP itself but <br>
with the languages it uses. ASP+ no longer uses scripting languages. If you previously used VBScript, all <br>
that code will be executed using the Visual Basic compiler. Visual Basic itself has had several <br>
significant changes in this revision and therefore creates additional compatibility issues. There are four <br>
known issues at this point, although additional ones may crop up as Visual Basic continues to change <br>
during development: <br>
Visual Basic no longer has default properties. You must now fully qualify all non-indexed properties to <br>
identify which property you want. Instead of writing "rsData("Name")" you must write "rsData<br>
("Name").Value." <br>
Tip: Prepare for this now by always explicitly specifying the property you want and not relying on the <br>
default property.<br>
<br>
Visual Basic no longer has both a set and a let. Set was originally introduced in Visual Basic 4 to <br>
differentiate between value assignments and object assignments. Some objects in Visual Basic 4 would <br>
return either an object or a string. The ActiveConnection property of an ADO command object is an example <br>
of this. Because of this dual nature, Set was needed to indicate an object assignment and Let was used to <br>
indicate the string assignment. With the elimination of default properties, however, this is no longer an <br>
issue. Instead of writing: <br>
Set cn = Server.CreateObject("ADODB.Connection")<br>
you can now write: <br>
cn = Server.CreateObject("ADODB.Connection")<br>
<br>
<br>
Visual Basic now requires parentheses around all subroutine calls. In previous versions of Visual Basic <br>
they could be used with a single argument but could not be used with more than one argument unless you <br>
used the Call keyword. In my code this is going to be the one that requires the most cleanup. The common <br>
case will be the use of Response.Write. Where I previously used it like this: <br>
Response.Write "Test: " & iCount<br>
it will now have to be called like this: <br>
Response.Write("Test: " & iCount)<br>
<br>
<br>
The way arguments are passed to subroutines and functions has changed from VBScript to Visual Basic. In <br>
VBScript arguments were passed ByRef by default. With Visual Basic arguments are passed ByVal by default. <br>
Tip: If you rely on the passing of arguments ByRef, explicitly include the keyword in your code to make <br>
your code more portable to <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a>+. <br>
Performance Considerations<br>
Although this is not strictly a migration issue, <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a>+ developers will see significant performance <br>
increases when porting their ASP code if they move all of their variable instances from loosely typed <br>
variants to strongly typed data types. This one change alone can yield significant performance increases. <br>
Additionally, rewriting existing COM components as managed code will eliminate many performance penalties <br>
due to marshalling and threading. <br>
In summary, <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a>+ offers some very cool new features but they aren't entirely free. Migrating from <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a> to <br>
ASP+ will require some work. However, careful attention to the aforementioned issues today will mean that <br>
your code ports much easier once <a href="http://www.biancheng88.cn/html/special/2008-11/ASP/" title="ASP" target=_blank><B>ASP</B></a>+ ships. <br>
<br>
<br>
Chris Kinsman is Vice President of Technology at DevX.com. He is reponsible for the site architecture, <br>
development, and day-to-day maintenance of the DevX network of sites <br>
 <br>

                 

原创粉丝点击