the complete webmaster
tutorials reviews reference
ASP
CGI
FrontPage
HTML
Java
JavaScript

Sponsored by El Scripto

Visit the Mortgage Loan Place for Home Loans and also click here to find VA Loans on our site.

Open software to automate your online business

home / articles / asp

Active Server Pages: Under the Hood

In last week's article, we discussed the basics of installing and using Microsoft's Active Server Pages (ASP).  We talked about some of the fundamental aspects of writing scripts that run within the context of the Active Server Pages environment and wrote our first server-side script , HELLO.ASP, using VBSCRIPT.

In this weeks installment, I'll discuss more of the overall capabilities of ASP.  We'll dig deeper into some of the features you can take advantage of and some of the tools you have at your disposal.  In addition, we'll spend some time laying the groundwork for the remainder of the articles in this series and give you a preview of some of the topics you can expect to hear about in the future. 

Internet Information Server and the ASP Development Platform

Microsoft's Internet Information Server (IIS) is an open platform designed specifically for creating powerful, scaleable internet and intranet applications.    However, IIS is not just a web server, it's much more.  IIS is a complete set of software components that provide the capability to develop robust data-driven web applications. 

ASP applications run within the context of IIS.  In simple terms, ASP provides the 'glue' that lets developers, like you and I, integrate these components and take advantage of their functionality in our applications. 

An Open Environment

Last week we wrote the obligatory "Hello World" application for ASP.  As you might expect of this example, it did nothing more than display a couple of lines of output consisting of an all-too-familiar phrase modified for our purposes, "Hello ASP World!".  For your convenience, I'll reprint the example here.


HELLO.ASP
<%@ LANGUAGE="VBSCRIPT" %>

<HTML>
<HEAD>
<TITLE>My First ASP Script!</TITLE>
</HEAD>
<BODY>

<% for x = 3 to 6 %>
<FONT SIZE=<% =x %>>Hello ASP World!</FONT><BR>
<% next %>

</BODY>
</HTML>


As you may recall, we spent a paragraph or so explaining aspects of the BASIC programming language, specifically a construct known as a for-next loop.   In our example, we actually used a language known as VBSCRIPT, a Visual Basic derivative tuned specifically for scripting on the web.

The important thing to remember is that we were not required to use VBSCRIPT, we could have used any compatible ActiveX Scripting language.  The ASP environment supports any ActiveX-compatible scripting language through the use of scripting "engines." Scripting engines are the plug-in objects that understand how to process scripts written in a given language. 

IIS includes native support for two of these engines: VBSCRIPT and JSCRIPT.   Languages such as Perl, REXX and Tcl are either now available or will be available in the near future for writing your version of  HELLO.ASP as well. 

You can even use multiple scripting engines in the same ASP script. Take a look at the example below:


<HTML>
<SCRIPT LANGUAGE=JScript RUNAT=Server>
...
</SCRIPT>

<SCRIPT LANGUAGE=VBScript RUNAT=Server>
...
</SCRIPT>
</HTML>


We'll take a look at scripting engines in a later discussion.   We'll also discuss more about the different methods for including script in our ASP code.  For now, remember that the default scripting engine is VBSCRIPT, and that any code you write that doesn't specify the desired engine will be processed by ASP as if it were VBSCRIPT.

Compile-Free Application Development

Another interesting aspect of our HELLO.ASP example is that it requires no compilation, at least on our part, prior to execution.  When I say 'compilation', I'm not necessarily referring to the translation of our script into a true executable image such as an EXE file type.  What I'm referring to is the process of opening the ASP script, processing the various script languages and converting that into some format useable and executable by the ASP environment.

Let's look at an example of how this interaction might take place.  Say you want to test HELLO.ASP and thus you request it from your server using the following URL syntax:

http://www.yourserver.com/hello.asp

First, your browser connects to IIS via TCP/IP and sends the required HTTP protocol  'Request' header indicating that it wishes to retrieve the file 'hello.asp'.   IIS has several 'extensions' loaded that enable it to filter requests for certain file types and take specific actions.  One of these file types is, as you might have guessed, files that end in .ASP.

Once requested, instead of simply retrieving the file and returning it to the requesting browser, IIS passes the file to the ASP environment for processing.   The ASP environment determines which scripting engines need to be loaded, loads them and passes to them the associated script.  The scripting engine then handles issues such as logic processing and flow of control and the creation of any additional objects required to satisfy the request.  Last but not least, any HTML generated by the script is returned to the requesting browser and the connection is broken.

This compile-free environment allows us a great deal of flexibility when developing ASP applications.  Most notably, the ability to immediately preview the results of your work by simply saving the ASP script and requesting it via the browser.

We'll talk more in the future about 'Request' headers and how they relate to ASP development, specifically how we can manipulate them ourselves with the ASP Request Object.

Browser Independence

It should come as no surprise that our HELLO.ASP program requires an ASP-compatible server to execute properly.  However, note that you can request HELLO.ASP using  just about any browser available on the market today so long as you can connect to your ASP-compatible server.

The reason should be obvious.  When our ASP program generated the HTML in response to the browser's request it contained only vanilla HTML.  No additional client-side support was required.  No <OBJECT> tags, no <APPLET> tags, just HTML.  For your convenience, I've included the HTML generated by our HELLO.ASP program.


<HTML>
<HEAD>
<TITLE>My First ASP Script!</TITLE>
</HEAD>
<BODY>
<FONT SIZE=3>Hello ASP World!</FONT><BR>
<FONT SIZE=4>Hello ASP World!</FONT><BR>
<FONT SIZE=5>Hello ASP World!</FONT><BR>
<FONT SIZE=6>Hello ASP World!</FONT><BR>
</BODY>
</HTML>


Application Partitioning and Components

Our HELLO.ASP example required very little logic to produce the above results.  But what if the three lines of output came from an external database, or possibly were the result of calling a function in an external component?

Using ASP, application development can be highly segmented.  Presentation logic and page layout can be decoupled from the corresponding business logic that typically runs on the server.  Using some of the built-in functionality of ASP, we will see later how to access this logic and how we can extend ASP to include other components including our own. 

ActiveX Server Components

So far, I've talked a lot about components without giving concrete examples.  When I refer to components, I'm referring to pre-compiled, binary code that complies with a specification known as The Component Object Model, or COM.  The source language for these components can be any language that supports compilation to the binary formats supported by COM.  Examples of these languages are :  C++, Visual Basic, Java, or COBOL.

IIS, no doubt, will continue to support CGI and ISAPI applications for some time to come.  However, Active Server (COM) Components offer a very rich programming model that provides a foundation for reusability and encapsulation of functionality and are becoming the standard means for modularizing web applications on this platform.

The Component Object Model (COM)

Let's catch up on some of our acronyms.  We were introduced to ActiveX and the Active Platform in our last article.  Now we need to introduce another technology called COM, or The Component Object Model.

If you take any advice at all from this column, please take the following advice with respect to COM - 'Learn it, know it, live it...".   Whether we like it or not, COM is becoming the defacto packaging for object technology delivered now and in the future on Microsoft platforms. 

COM is a specification that defines, for Windows platforms at least, how objects are created and destroyed and how you access their functionality, in other words, how you call or invoke their methods.  I'll save a more complete discussion of COM for a later article, however, for purposes of our discussion, just think of COM as yet another kind of 'glue' - the kind that holds objects together. 

ActiveX, on the other hand,  refers to a loosely defined set of COM-based technologies.   In this case, ActiveX Server Components, refer to COM-based server technologies written to this popular standard and accessible from many environments - including ASP.

Objects and Active Server Pages

Fortunately for us, a great deal of the internal functionality of ASP can be accessed via the use of objects.  Through these objects, ASP does the grunt work involved in setting up the runtime environment in which your script executes.

For instance, a great deal of information is available to you in the raw HTTP Request Header sent to you by the requesting browser.  The ASP Request Object provides access to this information and other  information passed into the script via this request such as cookies, form fields, and URL queries.

Another object, the ASP Response Object is used to send information back to the requesting browser such as any HTML required to construct the page, any setting for cookies and any configuration parameters dealing with page expiration.

We will look further at the Request and Response objects in a later article.   For now, it's important to remember that they are primarily used to hide the complexity of the HTTP protocol both from an inbound and outbound perspective and are used primarily in the transfer of  information between the requesting browser and our ASP script.

State Management in ASP Applications

HTTP is, by definition, a state-less protocol.  In other words, a browser makes a request, the request is satisfied in some way,  then you are disconnected from the server, usually with very little indication that you were ever there.

When I refer to 'state', I'm referring to your application's ability to 'remember' things as an end-user moves from page to page or from request to request, things relating to what you did when you were there.  For example, products purchased so far or a running total of responses on an online survey might be state information that you need to remember.

ASP provides state-management objects that allow you to store information in an associative array on the IIS server for each user session using your application and for the entire web application itself.

We'll discuss the Session Object and the Application Object later.  Just remember that they offer the kind of continuity in your application that a global variable would offer and give you the ability to keep information handy across the invocation of scripts.

Server-Based Functionality

There will be times when you want to access some functionality on the web server.  For those times, you will need the Server Object.  This object provides access to the creation of COM objects via the CreateObject method and will become more important as your object strategy matures.

Base Components Provided with IIS 3.0

Additional components are provided  with IIS that you can take advantage of via ASP.  Each component is accessible from ASP via the CreateObject method, which we'll cover in more detail in a later article. For now, I'll list each one and offer a brief description:

Active Data Objects (ADO) Provides high-speed database connectivity via ODBC and OLEDB database drivers.
Filesystem Component Provides read/write access to server-based files.
Content Linking Component Automatic and dynamic generation of contents pages from a file containing URLs.
Browser Capabilities Component Used to determine capabilities such as Frame, Table and ActiveX support of the requesting browser
Ad Rotator Component Used in conjunction with a series of image files that contain advertisements that 'rotate' between invocation of scripts.

Development Environments for ASP Applications

To date, all of our development of HELLO.ASP has been done using a text editor such as the Windows Notepad.  With the release of Microsoft's Visual Studio 97, there is now a sophisticated environment in which web applications using ASP can be developed and deployed.

Visual Studio is a comprehensive, one-stop-shop for web application development that packages the entire suite of Microsoft development tools into a single, all-inclusive environment.  Also known as Developer Studio, this environment allows a development project to include not only web application source files, but other complete projects such as Visual C++ and Visual J++ as well.

We'll take a look at what goes on behind the scenes when developing web applications in one of our future articles.  Until then, remember that there are other environments that support ASP development.  One very popular choice is Microsoft FrontPage98, another choice might be HomeSite 2.5 from Allaire Corporation.

Summary

In this article, we've taken another major step drilling deeper into the Active Server Pages environment.  We've talked about IIS and ASP and how they combined form a powerful environment for developing component-based web applications.

In addition, we've covered a great deal of the architectural aspects of application development such as the built-in ASP objects and additional objects included in IIS. As we proceed, however, there will obviously be more to explore.

Beginning next week, we'll take a look at each of the built-in objects in detail.  We'll see some examples of how to connect your web page with an ASP script and how to POST HTML form-based data to the Request object.  We'll also explore how these intrinsic objects can be access from your COM-based component.

As always, I appreciate having you as my guest and appreciate any feedback you may have.  See you next week!

Author: Keith Cox
Date: 12/29/97

More articles about Active Server Pages
More articles by Keith Cox
Author Biography

Get thousands of people selling your product online for FREE
write for us about us advertise

Copyright 1997, 1998 A Big Lime. All rights reserved.

body>