Introduction to Active Server Pages
Understanding ASP Basics
6/1/98
by Buz Warmkessel
What do Barnes and Noble, Eddie Bauer, Dell, MSNBC, and Quicken have in common? Their content may not be very similar, but they're all using Active Server Pages (ASP) to build sophisticated, database-driven web sites. But what is ASP, and why would you want to use it?
ASP was "born" in November 1996 when Microsoft announced its design of an Active Platform. The Active Platform reflects Microsoft's ideas about how a desktop computer and a server computer should communicate. It consists of two parts: the Active Desktop and the Active Server. The Active Desktop refers to the client side, or the user's side, where HTML files are displayed on a web browser. The Active Server refers to the server-side component. This consists of pages that can be interpreted by the server, hence the term Active Server Pages.
Microsoft's documentation describes ASP as "a server-side scripting environment that you can use to create and run dynamic, interactive, high-performance Web server applications." ASP files combine HTML, scripts, and ASP code to enable a much higher degree of interactivity than is possible with plain vanilla HTML. With ASP, programmers working on Windows NT can tailor the way pages are displayed based on outside information. A different image could be displayed each day of the week, or information could be displayed based on a user's age. This process, which is called condition branching, allows ASP to make decisions about what to display based on certain criteria.
HTML, on the other hand, has no way to make this type of decision. It's a display language. In the real world, you'll probably want to interact with users through a web storefront or personalize their experience by offering tailored content. For this, you need the ability to make decisions.
How Files Are Interpreted
Normally, HTML files are "interpreted" on the client side (in a user's web
browser). With Microsoft's Active Platform, the server can also interpret
files. Interpreting to a server means that before displaying a file in a
user's browser, the server will complete some initial steps:
Let's take the example of a shopping cart. Imagine a customer has selected five items from the store's catalog. These selections are listed together on one "shopping cart" page, which contains a table with rows and columns. At the top of each column is a heading, such as quantity, description, stock number, or price. How will you construct this page, considering that parts of it are dependent on what the customer has chosen?
The column headings can be included in the original HTML layout, since they won't change. The table's position probably won't change either, so it can also be incorporated into the original HTML file. These elements of the page will remain the same, regardless of how many times you come back and view the page.
The information inside the table (the list of what has been selected for purchase) will change, however. Each person viewing the site may select a different set of items. To display this information, ASP pulls the item information from a database and adds that item information to the HTML layout before it is sent back to the user's browser. Programmers use the term "on the fly" for this type of page, because it doesn't exist on its own. Instead, it is created on demand ("on the fly") when needed. The ASP script creates the entire page, by combining the static page elements with selected information from the database.
Using Scripts to Extend ASP
VBScript, JavaScript, and JScript are scripting languages that, when added
to an HTML file with SCRIPT tags, will allow for some tailoring of
display. These languages generally are run on the client side; in other words, they are
run by the browser when called for.
Used on their own, they have some serious drawbacks.
Despite these drawbacks, scripting languages can be useful. Possibly their best use is in validating data; for example, guaranteeing that certain fields have been filled out within a form before the data is sent back to the server for processing. This is done by having a script run when someone clicks on the submit button of a form. The function would check all of the form's required fields. If any of the required fields were left empty, the script would display an alert message informing the user that they had left a field blank.
Scripts can be used on the server side, but they are more commonly used on the client side. There is an attribute of the SCRIPT tag that allows the programmer to determine where the code is to be interpreted. The default is to process all code in SCRIPT tags on the client side (in the browser), but the programmer can set the attribute so that scripts are processed on the server.
Components and Objects
Components and objects are the tools used to communicate with the server's
environment and system. A component can contain one or more objects. An
object can have one or more methods and one or more properties. (Tip:
methods are sort of like verbs, and properties are like adjectives.) By
creating an instance of an object, you can use its methods to perform
tasks. Changing an object's properties will cause its methods to perform
tasks differently.
Several objects are built into ASP, some are built into VBScript, and some are built into the server's system. Other components can be created to further customize an application.
| Common Components and Objects | ||
|---|---|---|
| Object or component | Function | Source |
| Request Object | Handles information coming from the browser | Built into ASP |
| Response | Handles information sent back to the browser | Built into ASP |
| Server Object | Provides access to some basic server services | Built into ASP |
| Application Object | Maintains information for the life of an application | Built into ASP |
| Session Object | Maintains information for the life of a session | Built into ASP |
| Text Object | Manipulates text files | VBScript Scripting Object |
| Error Object | Provides for error analysis | VBScript Scripting Object |
| Dictionary Object | Creates a lookup reference | VBScript Scripting Object |
| File System Object | Provide access to file system | VBScript Scripting Object |
| Content Linking | Imparts an order to the pages on a site | Server Component |
| Browser Capabilities | Specifies what a user's browser can do | Server Component |
| Ad Rotator | Rotates several ads in a spot on the page | Server Component |
| Voting | Collects information from a user poll | Server Component |
| Active Database | Provides communication with a database | Server Component |
Potential Drawbacks
ASP is a powerful tool for dynamic web content, but like other solutions,
it does have some drawbacks. ASP is only available for Windows (NT and 95).
It has traditionally required that you be running a Microsoft web server
(generally Internet Information Server), though that may change with a
product called Chili!ASP, which is marketed as ASP for other servers. ASP
also uses cookies, which means people using the Lynx browser can't access
pages. However, the number of people using Lynx is very small, and they may not be a significant part of your target audience.
Depending on your situation and needs, ASP might be the best solution for you. ASP does have competition, mainly from a product called Cold Fusion. Cold Fusion, made by Allaire, will also let you talk to databases such as an Access file or SQL Server. However, Cold Fusion's tags can be very confusing and difficult to debug, and some people report memory leaks.
To find out more about ASP, you might want to pick up a copy of Active Server Pages 2.0, join an ASP-related mailing list, or contact a knowledgeable ASP programmer. Try starting with the resources mentioned in this guide.
Resources
ASP Diagram
http://www.ahref.com/images/daily/199806/AspDrawing.gif
A diagram showing how ASP works.
Sample ASP Code
http://www.ahref.com/guides/technology/199806/0601buzsample.html
Sample ASP code with explanations.
Roadmap
http://iis3.activeserverpages.com/iasdocs/aspdocs/roadmap.asp
Microsoft's official ASP documentation.
ActiveServerPages.com
http://www.activeserverpages.com
Self-described "best ASP resource in the world." Check out their ASP Quick Lessons.
15 Seconds
http://www.15seconds.com/
Top ASP resource featuring articles, news, and much more.
The ASP Hole
http://www.asphole.com/asphole/default.asp
A guide to ASP and IIS resources.
Site Builder Network: Server: ASP
http://www.microsoft.com/workshop/server/toc.asp#asp
Articles and white papers on ASP from Microsoft's Site Builder Network.
Microsoft Scripting Technologies
http://www.microsoft.com/scripting/default.htm
Information and tutorials on scripting, including VBScript and JScript.
Creating ASP Pages
http://www.montreat.edu/aspsamp/tutorial/atumd1.asp
A tutorial that shows how to create the popular "Hello World!" script.
ServerObjects
http://www.serverobjects.com
Extensive collection of ASP components.
15 Seconds: Component Section
http://www.15seconds.com/component/default.htm
Tips, downloads, and news about components to use with ASP.
Professional Active Server Pages
http://rapid.wrox.co.uk/books/0723/0723.asp
The site for the top ASP book, Professional Active Server Pages. Includes sample code and live examples.
Chili!Soft
http://www.chilisoft.net
Creators of Chili!ASP, a product that makes ASP available for a variety of web servers.
ListServs for Active Server Pages
http://www.activeserverpages.com/listserv/
Describes several ASP-related mailing lists you can join, including an ASP newbies list.
Buz Warmkessel has been a freelance computer applications consultant/programmer for
the last 12 years. He speaks five computer languages and four human ones.
You can email Buz with questions.
© 1998-1999 Anchor Productions, Inc. All rights reserved.