Trademarks: Microsoft and Windows are registered trademarks of Microsoft Corporation. Disclaimer: PCAnswers.org is not affiliated with Microsoft Corporation, nor claim any such implied or direct affiliation. The information contained on this site is for informational purposes only. The owners of this site are compensated by relationships with the recommended software products.
Please also recognize that the comments depicted on this site are not real. Rather, the comments are based on what some people have achieved with this product.
© PCAnswers.org 2017.
Scott Mitchell 4guysfromrolla.com November 2001 Summary: This document begins with an examination of a typical data-driven ASP application and then discusses porting the ASP application to ASP.NET. (13 printed pages) Objectives. Running ASP and Microsoft ASP.NET on the same Web server. Examining a common ASP application. Porting the ASP application to ASP.NET Assumptions The following should be true for you to get the most out of this document:. You are familiar with Microsoft® Visual Basic® programming concepts and terms. You are familiar with ASP Contents Running ASP and ASP.NET on the Same Web Server One of the first things you are likely to notice when working with ASP.NET is the new file extension: ASP.NET pages use.aspx, as opposed to the.asp extension used with ASP.
Additionally, when an ASP.NET page is requested, IIS hands off the request to the aspnetwp.exe process; ASP uses asp.dll. ASP and ASP.NET can both be used on the same Web server. That is, a Web site or Web application within a site can contain both ASP.NET pages and ASP pages. Because both ASP and ASP.NET pages can be accessed from the same Web server, you are not required to port your existing ASP pages over to ASP.NET-compatible pages. However, there are many advantages to porting your application from ASP to ASP.NET. Some of the biggest advantages include:.
Increased performance: Microsoft tests have shown that ASP.NET applications can handle two to three times the requests per second as classic ASP applications. Increased stability: Processes are closely monitored and managed by the ASP.NET run time, so that if one misbehaves (leaks, deadlocks), a new process can be created in its place, which helps keep your application constantly available to handle requests. Increased developer productivity: New features like server controls and event handling in ASP.NET help developers build applications more rapidly and in fewer lines of code. It is also easier than ever to separate code from HTML content. Unfortunately, porting existing ASP pages to ASP.NET pages is almost never as easy as simply renaming the file extension from.asp to.aspx because, among other factors, there are significant differences between Microsoft Visual Basic Scripting Edition (VBScript) and Visual Basic.NET. The good news is that most of the needed changes are syntactical and automatic.
Visual Basic.NET code that uses COM components (such as ADO or custom COM components you may have written) can virtually be left as is; C# code, however, requires a bit of extra code to work with COM components, which is beyond the scope of this document. This document, which is divided into two sections, begins with an examination of a typical data-driven ASP application. In the later section, you'll look at porting this ASP application to ASP.NET. Note This document focuses on porting an ASP application to ASP.NET with as few changes to the original ASP code as possible; it does not examine rebuilding an ASP application from the ground up, using features new to ASP.NET. Examining a Sample ASP Application The sample ASP application that you will be porting to ASP.NET is a Project Report Application for a fictional company. The application is written in VBScript.
This typical application displays information about ongoing and past projects, allowing the user to specify certain requirements on the Project Report display. This ASP application is data-driven, as the project information is stored in a database; specifically, two database tables are used: Project and Department. The Department table contains information about each department in the company and the Project table contains information about each project, such as: project name, start date, estimated completion date, actual completion date, priority, the department in charge of the project (via a foreign key to the Department table), and a thorough project description. A user browsing to the Project Information Web page is shown a listing of projects that were started in the past year. Two list boxes allow the user to customize the view of the current projects. The first list box lets the user specify to view ongoing, completed, or all projects.
(An ongoing project is one whose completion date is NULL, and a completed project has an actual and past completion date.) The second list box permits the user to further customize the report by viewing projects by a particular department. Figure 1 shows the project report user interface. In this instance, the user has opted to view all ongoing projects for the Internal Computer Services department. A report of the Internal Computer Services Department's ongoing projects Examining the Project Report Code The source code for the entire Project Report application is encompassed within a single ASP page, which uses a postback form to handle the user's report customization options.
Because this document focuses on porting an ASP application to ASP.NET, an explanation of how the ASP code works is not included. It is assumed that you have a working knowledge of how ASP and ADO data access are used to build applications today. The following code shows an ADO Connection object being created and opened to a Microsoft Access database. Set objDeptListRS = Server.CreateObject('ADODB.Recordset') objDepartmentListingRS.Open 'Department', objConnadOpenForwardOnly, adLockReadOnly, adCmdTable 'Iterate through the Recordset Response.Write 'Department: ' & ' Response.Write ' & '- Show All Departments -' & vbCrLf Do While Not objDeptListRS.EOF Response.Write ' & objDeptListRS('DepartmentName') & ' objDeptListRS.MoveNext Loop Response.Write ' & vbCrLf & vbCrLf Next, a dynamic SQL query is constructed based on the options selected by the user. Note in the following code that the SQL query's WHERE clause is created so that it always retrieves only those projects that began in the previous year. Based upon the user's selections, the WHERE clause is potentially extended further. The variables iDepartmentID and strProjectView are variables defined earlier and assigned to the list box values selected by the user.
StrSQL = 'SELECT D.DepartmentName, ProjectName, ' & 'StartDate, EstimatedEndDate, ActualEndDate, ' & 'Priority, ProjectDescription ' & 'FROM Project P ' & 'INNER JOIN Department D ON ' & 'D.DepartmentID = P.DepartmentID ' & 'WHERE StartDate = #' & DateAdd('yyyy', -1, Date) & '# ' 'Now, construct addition WHERE clauses if needed If CInt(iDepartmentID) -1 then 'Add a clause for the department ID strSQL = strSQL & ' AND P.DepartmentID = ' & iDepartmentID End If 'What types of projects do we want to view? Select Case strProjectView Case 'ongoing': strSQL = strSQL & ' AND ActualEndDate IS NULL' Case 'completed': strSQL = strSQL & ' AND ActualEndDate IS NOT NULL' End Select Another Recordset object, objProjectsRS, is created and populated with the results of the above dynamic SQL query. Finally, this recordset is iterated through and displayed as an HTML table. 'Output the HTML table tag and th tags Response.Write ' & vbCrLf Response.Write 'ProjectStartDate' & 'Estimated CompletionActual ' & 'CompletionPriority' & 'Description' & vbCrLf 'Loop through the entire Recordset Do While Not objProjectsRS.EOF 'Display the Recordset information objProjectsRS.MoveNext 'move to the next record Loop Response.Write ' & vbCrLf & vbCrLf Porting the ASP Application to ASP.NET When porting an ASP application to ASP.NET, you will need to decide how much time you want to spend incorporating the new features of ASP.NET into the existing ASP application.
Changing an ASP page's file extension from.asp to.aspx and correcting for some syntactical changes is usually enough to get an ASP page working as an ASP.NET page. Such a port, although it can be completed quickly, does not take advantage of many of the new features of.NET, including ASP.NET Web controls, Microsoft ADO.NET, the Microsoft.NET Framework classes, etc. Although a more complete port may take more time, your finished ASP.NET pages will be readable and maintainable, and more feature-rich. As a developer, you need to weigh the tradeoffs when deciding what approach to take when moving an ASP application to ASP.NET.
If you are pressed for time, a simple port from ASP to ASP.NET may be in order; if no such deadline looms, it may be worthwhile to take the time to build a rich ASP.NET application from the ground up. You can also, of course, take an incremental approach.
If you ran a large site that utilized a number of COM components to implement business rules, you may decide to port over just the UI portion of your Web application, and continue to use the classic COM components. In this next section, you will examine porting the existing ASP code to ASP.NET, making as few modifications as possible. Porting ASP Applications to ASP.NET To port an existing ASP application to ASP.NET, the first step is to rename the file extension of the ASP pages from.asp to.aspx. Because the Project Report Application has a single ASP page, this renaming task is simple enough. Once you've made this change, take a moment to visit the new.aspx page through your Web browser.
Did it load without error? Most likely not; chances are your VBScript code contains some syntactical problems. When porting the ASP application we examined earlier, the first error message you will receive is an error concerning Option Explicit, as shown in Figure 2. Option Explicit statement error message This statement, for an ASP.NET Web page, should be moved to the @Page directive. At this point, edit the.aspx file by removing lines 1 and 2 and replacing them with the following @Page directive.