IBM Computer, Laptops and Servers

Back Homepage Content Directory Resource Guide Blog

Converting ASP to ASP.NET

Laptop Battery

What is ASP ASP stands for Active Server Pages. Active Server Pages are HTML pages with embedded ASP scripts that are processed on the server before the page is sent to the user. ASP allows you to create dynamic database driven pages, a user can access data in a database, and interact with page objects such as Active X or Java components. How does ASP work When you type a URL in the Address Box or click on a web page you are asking the web server to send a file to your computer; if the file is standard HTML, then, when your web browser receives the web page it will look exactly the same as it did on the web server. However if an ASP file is sent to your computer from the web server, firstly, the server will run the HTML code; and then, run the ASP code. the ASP code could be the current date, or time; and other such information.

Thinkpad Converting ASP to ASP.NET

Computer memory is the quickest, cheapest, and easiest way to improve the performance of your system. Find RAM memory upgrades for desktops, laptops, servers, and printers all backed by a lifetime warranty and guaranteed compatible with your computer. Shipping is an everyday low price of $1.99! Computer Memory Outlet sells memory compatible with all leading computer manufacturers like Dell, Apple, Compaq, HP, Sony, IBM, Lenovo, and many more.”

Microsoft Upgrading to Microsoft .NET

As a rental organization ICC has kept strong focus on service by following strict quality control procedures and providing 24 hour a day, 7 day a week technical support on every computer rental. Feel secure when renting a computer from iccrents.com. Rent Laptops from Quick, 1000 laptops in stock, HP, CPQ, Dell, IBM, 24x7 Support, Same Day deliveries available nationwide. 20 years of experience.

Laptop Computers Scott Mitchell
4guysfromrolla.com

Active Server Pages (ASPs) side scripts in addition to the usual mixture of text and HTML (Hypertext Markup Language) tags. To distinguish asp web pages from normal HTML pages, Active Server Pages are given the ".asp" extension.

Laptop Computer November 2001

Description Have a friend with a laptop Do they always complain about the heat Cool them down with HandStands' Cool Lift. Designed to help promote air flow and reduce heat, the Cool Lift is perfect for notebook computers with the latest hot processors from Intel, AMD, Motorola, or IBM. Proof Shields for Laptops help prevent scratches from normal laptop use. Proof Shield. It even completely disappears when applied!

Desktop Computer Summary: This document begins with an examination of a

Notebooks typical data-driven ASP application and then discusses porting the ASP

Lenovo application to ASP.NET. (13 printed pages)

Hard Drive Objectives

Travelstar Running ASP and Microsoft ASP.NET on the same Web server

Gateway Examining a common ASP application

Laptop Parts Porting the ASP application to ASP.NET

Software Assumptions

Hard Drives The following should be true for you to get the most out of this document:

Electronics You are familiar with MicrosoftVisual Basicprogramming concepts and

Canon terms

Desktop Pc You are familiar with ASP

Desktop Computers Contents

Think Pad


Repair Running ASP and ASP.NET on

Data Recovery the Same Web Server

Cisco One of the first things you are likely to notice when working with ASP.NET is

Keyboard the new file extension: ASP.NET pages use .aspx, as opposed to the .asp

Monitor extension used with ASP. Additionally, when an ASP.NET page is requested, IIS

Desktop hands off the request to the aspnet_wp.exe process; ASP uses asp.dll.

Infosys ASP and ASP.NET can both be used on the same Web server. That is, a Web site

Refurbished Laptops or Web application within a site can contain both ASP.NET pages and ASP pages.

Wipro Because both ASP and ASP.NET pages can be accessed from the same Web server, you

Lap Top are not required to port your existing ASP pages over to ASP.NET-compatible

Refurbished pages. However, there are many advantages to porting your application from ASP

Memory to ASP.NET. Some of the biggest advantages include:

Intel Increased performance: Microsoft tests have shown that ASP.NET

As400 applications can handle two to three times the requests per second as classic

Averatec ASP applications.

Hardware Increased stability: Processes are closely monitored and managed by

Dual Xeon the ASP.NET run time, so that if one misbehaves (leaks, deadlocks), a new

Storage process can be created in its place, which helps keep your application

Seagate constantly available to handle requests.

Computer Sales Increased developer productivity: New features like server controls

Computer Hardware and event handling in ASP.NET help developers build applications more rapidly

Printers and in fewer lines of code. It is also easier than ever to separate code from

Technology HTML content.

Mainframe Unfortunately, porting existing ASP pages to ASP.NET pages is almost never as

Samsung easy as simply renaming the file extension from .asp to .aspx because, among

Computer Repair other factors, there are significant differences between Microsoft Visual Basic

Used Computers Scripting Edition (VBScript) and Visual Basic .NET. The good news is that most

Network of the needed changes are syntactical and automatic. Visual Basic .NET code that

Digital Cameras uses COM components (such as ADO or custom COM components you may have written)

Desktops can virtually be left as is; C# code, however, requires a bit of extra code to

Cognos work with COM components, which is beyond the scope of this document.

Hosting This document, which is divided into two sections, begins with an examination

Netfinity of a typical data-driven ASP application. In the later section, you'll look at

Internet porting this ASP application to ASP.NET.

Cheap Computer Note   This document

Digital Camera focuses on porting an ASP application to ASP.NET with as few changes to the

Printer original ASP code as possible; it does not examine rebuilding an ASP application

Xseries from the ground up, using features new to ASP.NET.

Maxtor Examining a Sample ASP

Data Storage Application

Hitachi The sample ASP application that you will be porting to ASP.NET is a Project

Rational Report Application for a fictional company. The application is written in

Websphere VBScript. This typical application displays information about ongoing and past

Battery projects, allowing the user to specify certain requirements on the Project

It Support Report display.

Western Digital This ASP application is data-driven, as the project information is stored in

Music a database; specifically, two database tables are used: Project and Department.

Networks The Department table contains information about each department in the company

Toner and the Project table contains information about each project, such as: project

Cheap Laptops name, start date, estimated completion date, actual completion date, priority,

Wholesale the department in charge of the project (via a foreign key to the Department

Brother table), and a thorough project description.

Netvista A user browsing to the Project Information Web page is shown a listing of

Camera projects that were started in the past year. Two list boxes allow the user to

Networking customize the view of the current projects. The first list box lets the user

Sharp specify to view ongoing, completed, or all projects. (An ongoing project is one

Cheap whose completion date is NULL, and a completed project has an actual and past

Windows completion date.) The second list box permits the user to further customize the

Monitors report by viewing projects by a particular department.

Linux Figure 1 shows the project report user interface. In this instance, the user

Computer Support has opted to view all ongoing projects for the Internal Computer Services

Used Laptops department.

Cameras

Scanners Figure 1. A report of the Internal Computer Services

Panasonic Department's ongoing projects

Workstation Examining the Project Report Code

Iseries The source code for the entire Project Report application is encompassed

Backup within a single ASP page, which uses a postback form to handle the user's report

Information Technology customization options. Because this document focuses on porting an ASP

Routers application to ASP.NET, an explanation of how the ASP code works is not

180gxp included. It is assumed that you have a working knowledge of how ASP and ADO

Notebook Battery data access are used to build applications today.

Security The following code shows an ADO Connection object being created and opened to

Lotus a Microsoft Access database.Set objConn = Server.CreateObject("ADODB.Connection")

Virus objConn.ConnectionString = _

Thinkpad T42 "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & _

Thinkpad 600 Server.MapPath("Projects.mdb") & ";"

Thinkpad 600e objConn.Open

Thinkpad 570 A recordset is populated with the Name and DepartmentID for

Thinkpad 600x each row in the Department table. The contents of this recordset are then

Thinkpad 390x displayed in a list box.Set objDeptListRS = Server.CreateObject("ADODB.Recordset")

Thinkpad A31 objDepartmentListingRS.Open "Department", objConn, _

Thinkpad X20 adOpenForwardOnly, adLockReadOnly, adCmdTable

Bios Update

Laptops 'Iterate through the Recordset

Toshiba Response.Write "<b>Department:</b> " & _

Laptop Battery "<select size=""1"" name=""lstDepartmentID"">"

Thinkpad Response.Write "<option value=""-1"">" & _

Microsoft "-- Show All Departments --</option>" & vbCrLf

Laptop Computers Do While Not objDeptListRS.EOF

Laptop Computer Response.Write "<option value=""" & _

Desktop Computer objDepartmentListingRS("DepartmentID") & """"

Notebooks 'Do we need to make the item SELECTED?

Lenovo If CInt(objDepartmentListingRS("DepartmentID")) = _

Hard Drive CInt(iDepartmentID) then

Travelstar Response.Write " selected"

Gateway End If

Laptop Parts

Software Response.Write ">" & objDeptListRS("DepartmentName") &_

Hard Drives "</option>"

Electronics objDeptListRS.MoveNext

Canon Loop

Desktop Pc Response.Write "</select>" & vbCrLf & vbCrLf

Desktop Computers Next, a dynamic SQL query is constructed based on the options selected by the

Think Pad user. Note in the following code that the SQL query's WHERE clause is

Repair created so that it always retrieves only those projects that began in the

Data Recovery previous year. Based upon the user's selections, the WHERE clause is

Cisco potentially extended further. The variables iDepartmentID and

Keyboard strProjectView are variables defined earlier and assigned to the list box

Monitor values selected by the user.strSQL = "SELECT D.DepartmentName, ProjectName, " & _

Desktop "StartDate, EstimatedEndDate, ActualEndDate, " & _

Infosys "Priority, ProjectDescription " & _

Refurbished Laptops "FROM Project P " & _

Wipro "INNER JOIN Department D ON " & _

Lap Top "D.DepartmentID = P.DepartmentID " & _

Refurbished "WHERE StartDate >= #" & _

Memory DateAdd("yyyy", -1, Date()) & "# "

Intel 'Now, construct addition WHERE clauses if needed

As400 If CInt(iDepartmentID) <> -1 then

Averatec 'Add a clause for the department ID

Hardware strSQL = strSQL & " AND P.DepartmentID = " & _

Dual Xeon iDepartmentID

Storage End If

Seagate 'What types of projects do we want to view?

Computer Sales Select Case strProjectView

Computer Hardware Case "ongoing":

Printers strSQL = strSQL & " AND ActualEndDate IS NULL"

Technology Case "completed":

Mainframe strSQL = strSQL & " AND ActualEndDate IS NOT NULL"

Samsung End Select

Computer Repair Another Recordset object, objProjectsRS, is created and populated with

Used Computers the results of the above dynamic SQL query. Finally, this recordset is iterated

Network through and displayed as an HTML table.'Output the HTML table tag and th tags

Digital Cameras Response.Write "<p><table align=""center"" " & _

Desktops "border=""1"" cellspacing=""1"">" & vbCrLf

Cognos Response.Write "<tr><th>Project</th><th>StartDate</th>" &_

Hosting "<th>Estimated Completion</th><th>Actual " & _

Netfinity "Completion</th><th>Priority</th>" & _

Internet "<th>Description</th></tr>" & vbCrLf

Cheap Computer 'Loop through the entire Recordset

Digital Camera Do While Not objProjectsRS.EOF

Printer 'Display the Recordset information

Xseries objProjectsRS.MoveNext 'move to the next record

Maxtor Loop

Data Storage Response.Write "</table>" & vbCrLf & vbCrLf

Hitachi Porting the ASP Application

Rational to ASP.NET

Websphere When porting an ASP application to ASP.NET, you will need to decide how much

Battery time you want to spend incorporating the new features of ASP.NET into the

It Support existing ASP application. Changing an ASP page's file extension from .asp to

Western Digital .aspx and correcting for some syntactical changes is usually enough to get an

Music ASP page working as an ASP.NET page. Such a port, although it can be completed

Networks quickly, does not take advantage of many of the new features of .NET, including

Toner ASP.NET Web controls, Microsoft ADO.NET, the Microsoft .NET Framework classes,

Cheap Laptops etc. Although a more complete port may take more time, your finished ASP.NET

Wholesale pages will be readable and maintainable, and more feature-rich.

Brother As a developer, you need to weigh the tradeoffs when deciding what approach

Netvista to take when moving an ASP application to ASP.NET. If you are pressed for time,

Camera a simple port from ASP to ASP.NET may be in order; if no such deadline looms, it

Networking may be worthwhile to take the time to build a rich ASP.NET application from the

Sharp ground up. You can also, of course, take an incremental approach. If you ran a

Cheap large site that utilized a number of COM components to implement business rules,

Windows you may decide to port over just the UI portion of your Web application, and

Monitors continue to use the classic COM components.

Linux In this next section, you will examine porting the existing ASP code to

Computer Support ASP.NET, making as few modifications as possible.

Used Laptops Porting ASP Applications to ASP.NET

Cameras To port an existing ASP application to ASP.NET, the first step is to rename

Scanners the file extension of the ASP pages from .asp to .aspx. Because the Project

Panasonic Report Application has a single ASP page, this renaming task is simple enough.

Workstation Once you've made this change, take a moment to visit the new .aspx page through

Iseries your Web browser. Did it load without error? Most likely not; chances are your

Backup VBScript code contains some syntactical problems.

Information Technology When porting the ASP application we examined earlier, the first error message

Routers you will receive is an error concerning Option Explicit, as shown in Figure

180gxp 2.

Notebook Battery

Security Figure 2. Option Explicit statement error message

Lotus This statement, for an ASP.NET Web page, should be moved to the @Page

Virus directive. At this point, edit the .aspx file by removing lines 1 and 2 and

Thinkpad T42 replacing them with the following @Page directive:<% @Page Language="VB" Explicit="True" %>

Thinkpad 600 Once this change is made, reload the page in the browser. You will receive

Thinkpad 600e another error concerning the lack of parenthesis around the Response.Write

Thinkpad 570 statements.

Thinkpad 600x

Thinkpad 390x Figure 3. Response.Write statement error message

Thinkpad A31 This generates an error since Visual Basic .NET requires that all argument

Thinkpad X20 lists to both subroutines and functions be encased in parenthesis. Check through

Bios Update the entire document and place parenthesis around the argument lists for all of

Laptops the Response.Write statements, and then reload the ASP.NET page in your browser

Toshiba once again.

Laptop Battery Another change from Visual Basic 6.0/VBScript to Visual Basic .NET is that

Thinkpad Visual Basic .NET does not support default properties. Default properties

Microsoft allowed developers a bit of a shortcutf, when using classic COM components in

Laptop Computers Visual Basic 6/VBScript, a developer failed to specify a property, the default

Laptop Computer property is used. For example, the default property of the ADO Recordset is the

Desktop Computer Fields collection, and the default property of a Fields collection

Notebooks is the Value property. Hence, when you use:Response.Write objRecordset("columnName")

Lenovo in classic ASP you are saying, in essence:Response.Write objRecordset.Fields("columnName").Value

Hard Drive When porting your classic ASP pages to ASP.NET, you may receive the following

Travelstar cryptic error message, Cast from __ComObject to String is not

Gateway valid.

Laptop Parts

Software Figure 4. ASP.NET porting error message

Hard Drives Such an error occurs because Visual Basic .NET does not support default

Electronics properties, when we use:Response.Write(objRecordset("columnName"))

Canon Visual Basic .NET is trying to cast the Fields object to a String,

Desktop Pc which it cannot do. Rather, we must indicate that we want to output the

Desktop Computers Value property by explicitly stating which properties we wish to

Think Pad output:Response.Write(objRecordset.Fields("columnName").Value)

Repair As you continue to port your ASP.NET application you will, invariably, come

Data Recovery across other syntactical errors. Table 1 summarizes the syntactical errors

Cisco encountered when porting the Project Report Application from ASP to ASP.NET.

Keyboard Note   Visual Basic has

Monitor matured as a programming language with the release of Visual Basic .NET. It now

Desktop supports tryatch error handling, true object-oriented development, and many

Infosys other enhancements that were long overdue. To modernize Visual Basic, though, it

Refurbished Laptops was necessary to make some syntactical changes to the language. Therefore,

Wipro Visual Basic .NET is not 100% backwards compatible with VBScript or Visual Basic

Lap Top 6. 0. For a detailed discussion on the changes in Visual Basic .NET, be sure to

Refurbished read .

Memory Table 1. Syntactical errors encountered when porting the

Intel Project Report Application

As400 Error

Averatec Reason

Hardware Resolution

Dual Xeon Option Explicit statement not valid inside a

Storage procedure.

Seagate Option Explicit needs to be defined in the Page

Computer Sales Directive using the Explicit attribute.

Computer Hardware Add <% @Page Explicit="True" %> to the

Printers top of the ASP.NET page.

Technology There can only be one Page Directive.

Mainframe When we added a Page Directive, the @LANGUAGE =

Samsung "VBSCRIPT" directive in our ASP page became redundant.

Computer Repair Remove the line containing <%@ LANGUAGE =

Used Computers "VBSCRIPT" %> and add the Language="VB" attribute to the Page

Network Directive.

Digital Cameras Argument lists in call statements must now be

Desktops enclosed in parenthesis.

Cognos Visual Basic .NET requires all subroutine calls to

Hosting enclose their parameters in parenthesis. A number of Response.Write statements

Netfinity do not contain such parenthesis.

Internet Add the needed parenthesis: e.g., change

Cheap Computer Response.Write str to Response.Write(str).

Digital Camera Let and Set statements are no longer supported on

Printer assignment statements.

Xseries Because Visual Basic .NET no longer supports default

Maxtor properties, the Let and Set keywords have been removed from the

Data Storage Visual Basic language.

Hitachi Remove any Let or Set keywords. (In the

Rational Project Report Application, the Set keyword assigns Connection and

Websphere Recordset objects to variables.)

Battery Date is a type, and so is not a valid expression. A

It Support variable, constant, or procedure is expected.

Western Digital In the Project Report Application the Date()

Music function was used to get the current date. This is no longer supported.

Networks Replace Date() with

Toner DateTime.Now

Cheap Laptops The name IsNull is not declared.

Wholesale Visual Basic .NET no longer supports the

Brother IsNull function. (Recall that in the Project Report Application, a

Netvista project is not completed if the actual completion date is NULL; in the ASP

Camera version IsNull is used to check whether or not the field was NULL.)

Networking To fix, replace IsNull with

Sharp IsDBNull.

Cheap Cast from __ComObject to String is not valid.

Windows Visual Basic .NET no longer supports default

Monitors properties, so when using classic COM components, be certain to explicitly fully

Linux state the properties you wish to use.

Computer Support Change instance of objRS("colName") to

Used Laptops objRS.Fields("colName").Value

Cameras COM Component Threading Concerns

Scanners Some issues can arise when using COM components within an ASP.NET page,

Panasonic specifically those COM components that have been marked as apartment-threaded or

Workstation COM objects that access the ASP-intrinsic objects (Request,

Iseries Response, Server, Application, and Session) through

Backup the ObjectContext object.

Information Technology For example, by default, the ADO objects are marked in the registry as

Routers apartment-threaded; when trying to use an apartment-threaded component through

180gxp an ASP.NET page, you will receive an error instructing you that the

Notebook Battery apartment-threaded component you attempted to create could not be created.

Security Figure 5 shows the ASP.NET port of the Project Report Application. Note that

Lotus this error is present because the ADO objects are, by default, marked as

Virus apartment-threaded.

Thinkpad T42

Thinkpad 600 Figure 5. An error occurs when attempting to access an

Thinkpad 600e apartment-threaded COM component through an ASP.NET page

Thinkpad 570 Fortunately, ASP.NET offers an ASP Compatibility mode, as the error message

Thinkpad 600x says. To turn on the ASP Compatibility mode, add the aspcompat=true

Thinkpad 390x attribute to the Page Directive. Adding this attribute accomplishes two things:

Thinkpad A31 ASP.NET uses Single-Threaded Apartment (STA) threads when accessing the COM

Thinkpad X20 component. The default is to use Multi-Threaded Apartment, or MTA, threading.

Bios Update ASP.NET provides access to the ASP-intrinsic objects in a

Laptops backward-compatible fashion.

Toshiba With these two changes, the ASP Compatibility mode allows ASP.NET to use

Laptop Battery apartment-threaded COM components or COM components that access the

Thinkpad ASP-intrinsic objects.

Microsoft Note   A

Laptop Computers thorough discussion on the COM threading models is beyond the scope of this

Laptop Computer document. For more information on the various COM threading models and their

Desktop Computer implications, be sure to read Understanding and Using COM Threading Models.

Notebooks Summary

Lenovo You have now examined how to port an ASP application to ASP.NET. As you can

Hard Drive see, porting an ASP page involves not much more work than simply renaming the

Travelstar page's file extension. Porting the Project Report Application from ASP to

Gateway ASP.NET, a one-page ASP application with 200 lines of code, took under five

Laptop Parts minutes. When porting your ASP applications to ASP.NET, be sure to keep the

Software following points in mind:

Hard Drives Be familiar with the syntactical changes from VBScript to Visual Basic .NET.

Electronics Guarding against small syntactical errors will make the process that much

Canon smoother.

Desktop Pc Add the aspcompat="true" attribute to the Page Directive if the ASP

Desktop Computers page you are porting uses apartment-threaded COM components or COM components

Think Pad that access the ASP-intrinsic objects. Otherwise this directive is not required.

Repair About the Author

Data Recovery Scott Mitchell is the founder and editor of , one of the

Cisco largest ASP resource sites on the Web. He has been avidly using and writing

Keyboard about Active Server Pages since January 1998. Scott has written several hundred

Monitor ASP and ASP.NET-related articles on 4Guys, along with authoring numerous

Desktop beginner- and advanced-level books on Active Server Pages and ASP.NET.

Infosys About Informant Communications Group

Refurbished Laptops Informant Communications Group, Inc. is a diversified media company focused

Wipro on the information technology sector. Specializing in software development

Lap Top publications, conferences, catalog publishing and Web sites, ICG was founded in

Refurbished 1990. With offices in the United States and the United Kingdom, ICG has served

Memory as a respected media and marketing content integrator, satisfying the burgeoning

Intel appetite of IT professionals for quality technical information.

As400 Copyright by Group and Microsoft Corporation

Averatec Technical editing: Paul Litwin, Litwin Consulting

Hardware

[ Comment, Edit or Article Submission ]

Share this:

Add To Yahoo MyWeb Add To Google Bookmarks Add To Furl Fav This With Technorati Add To Newsvine Add To Bloglines Add To Ask Add To Windows Live Add To Slashdot Stumble This Digg This Add To Del.icio.us Add To Reddit

More about:

Nov December 2008 Jan
Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

IBM Computer, Laptops and Servers Blog on Technorati Related Blog of IBM Computer, Laptops and Servers on Sphere
Content Directory
Resource Guide


Adobe Software Official Online Store

Website Links
IBM Computer, Laptops and Servers Copyright © 2008 www.ibmfans.com. All rights reserved. Site Map
Homepage | Blog | Advertise | Privacy Policy | Disclaimer | Contact Us | Links