Page

2.4.1- ASP Objects and Components

  by NT Community Manager.
Last Updated  by Jim Minatel.  

<< 2.4.0- What does ASP do for us?Chapter22.5.0- The Alternatives To ASP >>

ASP Objects and Components

ASP provides a compendium of objects and components, which manage interaction between the web server and the browser. For now, you can think of an object as being a neatly-packaged box, which contains a set of related functions and pieces of information, and you can think of a component as being a package of related objects. (Often, objects are grouped together into a single component so that they can be marketed as an application.) We'll take a more thorough look at objects in Chapter 6 , and we'll build some components of our own in Chapter 16 .

The ASP 'objects' can be manipulated by scripting languages. Take a look at the following diagram:

 

543636_pg85.jpg

ASP functionality is divided up into seven intrinsic objects, each of which manages its own part of the interaction between the web client and web server. When we write ASP code, we use six of these objects – as you'll see over the course of the book, they are fundamental elements of our code, because they're what we use to program ASP actions. The seventh, the ASPError object, is used by IIS to handle errors and generate appropriate information about them. The components, by contrast, are self-contained pieces of functionality that are written specifically for ASP – each is a special add-on tool that allows the ASP author to achieve particular tasks, using ASP capability.

Let's take a quick tour through all of the different objects and components that come as part of ASP.

The ASP Intrinsic Objects

There are seven ASP intrinsic objects, which each deal with a specific aspect of interactivity: they are called Request, Response, Server, Application, Session, ASPError and ObjectContext. We'll look at each of these objects in much more detail over the Chapters 7 , 8 , 9 and 17 , but for now we'll just explain them very briefly – because we'll begin to get used to using them as we progress through general scripting techniques in Chapters 3 , 4 , and 5 .

 

The Request and Response objects are, in a sense, the most self-explanatory. They represent the movement of information from client-to-server, and from server-to-client:

 

  • The Request object is used to deal with a request that a user makes – that is, when they ask the browser to see a particular web page or web application. The 'request' might be made in the form of input from an HTML form, or just by typing in a URL.
  • The Response object is used to deal with the server's response back to the browser. We've already seen an example of this, when we used the syntax Response.Write "Hello!". When we write this, we're asking the web server to write the characters Hello! into the HTML that is to be returned to the browser. The functionality for writing into the HTML output is encapsulated into the method called Write which, logically, is contained within the Response object.

 

The other objects work more in the background to further enhance the functionality available in ASP:

 

  • The Server object is used represent the web server itself. Thus, it provides several commonly-used functions relating to things that the web server might do – such as creating new objects and setting timeout properties for scripts. There are also methods for translating character strings into the correct format for use in URLs and in HTML, by converting non-legal characters into the correct legal equivalent.
  • The Application object is used to represent the web application (roughly speaking, a collection of related web pages hosted by the web server). Thus, we can use it to manage things like the contents of the application.
  • The Session object is used to represent the user's session (essentially, the 'experience' that the user has while browsing a number of pages within the same web application), and to store information about that session. We can use the Session object to manage things like the maximum time that the web server will wait between user 'requests', before terminating the session (and releasing the information relating to that session).
  • The ObjectContext object is used to manage transactions. It started out solely as part of ASP, but now has been integrated into the Windows 2000 operating system as a whole (along with Microsoft Transaction Server – a package with which it was closely related). It encompasses all of the other ASP objects, and you can reference each of them through ObjectContext. We'll talk about transactions and the ObjectContext object in Chapter 17.
  • The ASPError object contains details of any errors generated by an ASP script or by the asp.dll itself.

 

We'll meet all of these objects formally, and learn how to use them, later in the book.

Active Server Components

Active Server components are components or DLLs that come freely with ASP (as opposed to components that are vended by third parties). They have a wide range of purposes, as you can see by the descriptions below. There are ten common components provided by Microsoft with IIS 5.0 (although different versions of the installation can add or remove components), and many more are available from third parties. We'll be looking at the most important ones in Chapter 11 . For now, here's a brief summary of the components and what they do:

 

  • The Ad Rotator component does exactly what you might expect – it's a rotator for the ads that appear on your page. More specifically, we use this component by supplying it with a list of images; it will arrange for one of the images to be displayed on the page each time the page is requested. It selects the images randomly, but takes account of a weighting factor, which reflects what proportion of the total number of requests should see that image. It also allows you to associate each image with a separate hyperlink, which takes the user straight to a related connected site by clicking.
  • The Browser Capabilities component references a file called browscap.ini, which details every version of every Microsoft and Netscape browser ever created. It uses this information to determine whether or not the browser currently used supports frames, tables, and so on.
  • The Content Linking component uses a text file to manage (and provide links for) a sequential set of web pages. It allows the administrator to provide extra information about each page in the sequence, and keeps the links in an orderly list so that they can be easily maintained. For example, it can be used to guide a visitor through a sequence of pages in a predetermined order.
  • The Content Rotator component is a slimmed-down version of the Ad Rotator component, which just displays text.
  • The Counters component creates an object that persists for the lifetime of an application and can be used to store, increment or retrieve a value. Counters are manually set, unlike page counters for example, which are set automatically, and persist until deleted.
  • The Logging Utility component allows your applications to be able to read from your IIS log files which monitor who has been connecting to your site.
  • The MyInfo component is used to store personal information about the server administrator.
  • The Page Counter component provides a page counter, which increments by one each time a page is accessed. This is an automatic process, rather than a user-defined one.
  • The Permission Checker component can be used to monitor whether a certain user has been given permission to read or execute a file.
  • The Tools component provides a set of properties that are loosely grouped under the catch-all heading of 'miscellaneous utilities'. Includes checks to see if a certain file exists or if a certain user is the site owner.

The Microsoft Data Access Components – MDAC

In addition to the components listed above, there is a special group of components that come as part of the operating system, along with ASP, and are known as the Microsoft Database Access Components (MDAC). This in turn contains a group of objects that are known collectively as the ActiveX Data Objects (ADO). It also contains several components that are essential to the viewing of all sorts of data (databases, text files, spreadsheets etc) on all sorts of different platforms.

 

ADO enables data access, and allows data to be viewed, manipulated and updated via web pages (and, indeed, in other ways too). At the time of writing, the latest version is ADO 2.5 – which comes as part of MDAC 2.5. We look at data access via MDAC and ADO in detail in Chapters 12 , 13 and 14 .

The ASP Scripting Objects

Finally, there are three objects called Dictionary, FileSystemObject and TextStream, which are provided in a separate library file, and known as Microsoft Scripting Runtime:

 

  • The Dictionary object is essentially a 2-column array, in which we might store a name/value or name/description pair on each row of the array.
  • The FileSystemObject object is a tool for manipulating drives, folders and files on the web server.
  • The TextStream object allows us to read the contents of a file as plain text.

 

We'll see more about these objects and some potential uses for them, in Chapter 10 .

<< 2.4.0- What does ASP do for us?Chapter22.5.0- The Alternatives To ASP >>

Copyright © 2003 by Wiley Publishing, Inc.

Powered by Near-TimeTerms of Services | Privacy Policy | Security Policy |