【VB/.NET】Converting VB6 to .NET 【Part III】【之一】

第一部分:

原文:

This is the third and final installment in a three-part series. In the first installment (.NETDJ, Vol. 2, issue 9), I covered general conversion issues, in the second installment (Vol. 2, issue 10), I finished general conversion issues, and covered issues associated with database conversions. In this final installment, I will cover ASP Web page conversions, converting to VB.Net 2005, converting to C#, and finally, I will cover some arguments for converting.

Converting ASP to ASP.NET

Converting from ASP to ASP.NET is probably the easiest of all .NET conversions because ASP Web pages can be used side-by-side with ASP.NET Web pages, meaning the conversion can be done on a page-by-page basis. This is because the ASP and ASP.NET engines, like many things in .NET, can run side-by-side. The server knows which engine to pass the page to because ASP pages have a .asp extension, and ASP.NET pages have a .aspx extension.

One exception to this is that ASP pages and ASP.NET pages are considered different applications in different sessions, so session variables and other session and application states cannot be shared. There are two solutions to this problem. The first is to convert all pages that share state information to ASP.NET as a group. The other option is to use a different method to share the information, such as a database, or the data can also be posted from one page to another, regardless of whether the pages are written in ASP or ASP.NET. Details on how to share states using databases can be found at http://msdn.microsoft.com/asp.net/using/migrating/ default.aspx?pull=/library/en-us/dnaspp/html/converttoaspnet.asp.

Another issue that complicates conversions is that while a single ASP page can use more than one server-side scripting language, each ASP.NET page is limited to a single server-side scripting language. Allowing mixed scripting languages was required with ASP because of limitations with scripting languages such as incomplete support for COM objects in JScript; this occasionally required adding VBScript to pages that otherwise would have been written completely in JScript. In ASP.NET, these limitations in JScript have been removed, making mixed scripting languages unnecessary in most cases. This should make JScripters happy, but it may generate extra work during the conversion process. Because client-side script, even that generated by server-side script, is executed on the client, it doesn't need support from ASP.NET and so is still allowed in ASP.NET.

Because ASP and ASP.NET pages can coexist, the simplest conversion strategy is to just start writing new pages in ASP.NET.

The next step is to just change the extension of a page from .asp to .aspx; because ASP.NET was designed to be compatible with ASP, simple ASP pages may run as ASP.NET pages without change.

Because ASP scripts are interpreted, and ASP.NET scripts are compiled, any scripts used by the page will typically run much faster without any other changes.


译文:

这是系列里三部分里最后一部分了。在第一部分里((.NETDJ, Vol. 2, issue 9)),我描述了一些常见的转换问题,第二部分((Vol. 2, issue 10)),我完成了一些常见的转换,并且描述了关于数据库的转换问题。这里,我将会描述关于ASP网页到VB.NET 2005、C#、的转换,最后,我还会介绍一些转换参数。

从ASP到ASP.NET

这类转换可能是所有.NET平台代码移植中最容易的了,因为ASP网页可以和ASP.NET网页一起使用,这意味着转换可以基于逐页的方式来完成。这要归功于ASP和ASP.NET引擎,使得可以像.NET中的许多东西一样并能跟它们一起运行。服务器知道是哪一个引擎传送了页面,因为ASP页面带有.ASP后缀,而ASP.NET的是.ASPX。

但是有一个例外,在不同的SESSION中ASP和ASP.NET页面被作为不同的应用来看待。所以SESSION变量、SESSION、应用状态不可共享。不过有两个解决办法。第一个是将所有共享同一个状态信息的页面作为一个组转换到ASP.NET平台。而另一个选择就是使用不同的方法来共享这些信息,比如数据库,或者将数据从一个页面POST到另一个页面,无论页面是用ASP还是ASP.NET写的。至于怎么使用数据库共享数据的细节,请访问: http://msdn.microsoft.com/asp.net/using/migrating/ default.aspx?pull=/library/en-us/dnaspp/html/converttoaspnet.asp

另一个使转换变得复杂的问题是,虽然当一个单一的ASP页面使用了超过一种的服务器端脚本语言,但是每一个ASP.NET页面还是被限制于一种服务端脚本语言。ASP需要使用混合脚本语言,由于每一种脚本语言都有其自身的限制,比如JScript对COM对象的支持不完整。有时候需要将VBScript添加进原先写好的Jscript页面里。而在ASP.NET中,这些JS中的限制已经被解决了,是的在大多数案例中混合脚本语言已经不必要了。这应该使JS脚本开发者很欢乐,但是这使得在转换过程中引起了额外的工作量。

不过客户端脚本,甚至是服务端生成的脚本,由于在客户机上运行,可以不需要来自ASP.NET的支持,所以不转换仍然是ASP.NET所允许的。

由于ASP和ASP.NET网页可以共存,那么最简单的转换方法就是开始在ASP.NET中编写一个新的页面。

接下来仅仅要将.ASP扩展名改成.ASPX,因为ASP.NET设计成兼容ASP,简单的ASP网页甚至可以无须改变就在ASP.NET上运行。

由于ASP脚本是解释型的,并且ASP.NET脚本是编译型的,所以任何页面所使用的脚本通常会运行地更快,而无须改变。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值