Migrating from ASP to asp+

Source: Internet
Author: User
Tags date execution iis include microsoft sql server connect one table tagname
Asp+ The original author: Rain Morning


Initial consideration (i)





It includes the configuration of the running platform, the creation of Pagelet, the use of new ado+, the use of new datasets for data access, the transformation of HTML forms to DataList, and the use of many other new server-side controls ... What are you waiting for? Now feel asp+ 's new charm! )





since Microsoft announced asp+ at the July 2000 Professional Developers ' conference, one of the same questions has plagued many newsgroups and discussion forums: "What do I need to do to convert an existing Web application from ASP to asp+?" A spokesperson for the professional developer's meeting said: there is no need to make major changes to the code, and the entire conversion process is not too difficult. Is that so? In this article, we will explore exactly.





to run the alpha version of asp+, you need:





Windows Professional Server, or Advanced Server





IIS5.0





Internet Explorer5.5





   .. NET Framework runtime (. NET Framwork Runtime)





(future releases of asp+ will be available on Windows NT and 9x)





If you are an ASP developer, the techniques you currently use such as VBScript will easily be converted to visual Basic. NET to
for your asp+ page




write code. You may also use other languages, such as c#,managed C + + or COBOL. In this article, I'll describe the detailed steps required to upgrade a small Web application from ASP to asp+. The sample code uses visual Basic. Net.





Although ASP and asp+ can co-exist with each other, we choose to migrate the entire site to asp+. The migration is a sample site that is used to demonstrate entry-level Web development. We feel that this site represents a significant portion of the current network of typical small and medium sites. The site URL is: http://www.codejunkies.net/eVille/, it is a virtual enrollment site, enrolled students will learn it-related courses. The site is built on the Windows2000 server, driven by the Access2000 database, uses VBScript, client JavaScript, and ASP3.0, and does not use COM.





on the same Web server running IIS5.0, ASP and asp+ are designed to support running in parallel (the final release version will support other versions of IIS). This means that we can migrate the entire site one page at a time. The original page can still run under ASP3.0, and the new page will be converted to use asp+ server controls and functions.





The first step we need to make is for IIS to be able to use Default.aspx as a valid default file. This step is fairly straightforward, in Internet Service Manager:





* Open the Properties dialog box in the IIS virtual directory





* Click the ' Add ' button in the ' File ' tab





* Input default.aspx





* click ' OK ' two times





The Eville site used for the example does not use COM, so all data access is done through ADO in ASP or include files. One of our initial goals is to transform ADO into ado+ to get better results from ado+ Managed provider. Asp+ supports the use of traditional ADO, but migrating to ado+ will benefit more. Let's say: Get more than one table (table) from a single dataset, faster execution speed, and bind data to server controls. Data access in asp+ pages can be done through ado,ado+ or SQL Managed provider. Since the sample site is not using SQL Server and we want to optimize execution, ado+ has become our best choice.





every page of this site involves data access, so it will make up the largest proportion of the conversion project. Basically, each page must make some code modifications to get and display the data needed for that page. There is a connect.inc file in the Eville structure that contains the ADO connection code, and it is available on every page. The connection has been built and ready to use. Because the process of connecting to a database and binding to a asp+ data control is done by a new Page_Load event in asp+, we now have to take a slightly different approach.








initial consideration (ii)








uses the same idea as creating a universal connection in a single module, we created a pagelet. Pagelet enables developers to create pseudo controls, which can be used to display properties, methods, and events as well as objects. Our solution is to create a pagelet that displays the Connecttodb method, which returns a ADOConnection object (slightly different from the syntax of ADO). We use the following code to create the Pagelet and save it as a connect.aspc (the extension indicates that it is a pagelet)





<%@ Import namespace= "System.Data"%>





<%@ Import namespace= "System.Data.ADO"%>





< script language= "VB" runat= "Server" >





public Function Connecttodb () as ADOConnection





Connecttodb = New adoconnection ("Dsn=evilledsn")





End Function





</script>





you will notice that we have imported two namespaces, namely System.Data and System.Data.ADO. In order to use the ado+ Managed provider these namespaces are necessary. Many people ask me a lot of questions about this, because most of the examples currently use SQL Managed Provider based on Microsoft SQL Server 2000 databases. For non-SQL Server databases, asp+ can use ado+ Managed Provider, which is roughly the same as the way you use ADO in your program. importing namespaces and creating references in VB Programs (Reference) are similar.




The use of
pagelet allows me to maintain the current site plan, and once the connection is created in the module, we can reuse the module wherever it is needed. This means that we need to replace the include file instruction with an instance of Pagelet, and then call the Connecttodb method when we need a database connection. In pages that require the use of pagelet, we first have to register (register) with the page using the asp+ directive. In the instructions, we define tagprefix,tagname, and source (SRC). Similar to the include file in ASP, TagPrefix and tagname are used where we place pagelet.





<%@ Register tagprefix= "Seven" tagname= "Connect"





Src= "_INCLUDES/CONNECT.ASPC"%>





the method of placing the pagelet we just registered is similar to the asp+ server control:





< [tagprefix]:[tagname] Id=mypagelet runat=server/>





For example:





< Seven:connect id=connect runat=server/>





in ado+, the concept of a Recordset (recordset) is replaced by a combination of datasets and DataViews. We will discuss these two concepts in a moment. Let's start with a look at how the code changes after the Default.asp page migrates to Default.aspx (asp+ page suffix). First Look at Default.asp:





<!--#include file= "_includes/connect.inc"-->





<%





Dim cneville_db, rsupcoming, strsqlupcoming





Set rsupcoming = Server.CreateObject ("ADODB. Recordset ")





strsqlupcoming = "SELECT Top 2" & _





"Classes.title, sessions.session_id," & _





"Sessions.special, Classes.description" & _





"From Classes INNER JOIN Sessions on" & _





"classes.class_id = Sessions.classid" & _





"WHERE ((sessions.date) >date ())" & _





"ORDER by Sessions.date"





Rsupcoming.open strsqlupcoming,cneville_db





%>





became a default.aspx in asp+:





<%@ Import namespace= "System.Data"%>





<%@ Import namespace= "System.Data.ADO"%>





<%@ Register tagprefix= "Seven" tagname= "Connect"







Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.