Working with Components

ActiveX server components, formerly known as Automation servers, are designed to run on your Web server as part of a Web application. These components allow you to extend the functionality of your script behind the scenes—no interface is involved in running them.

Server components are typically invoked from Active Server Pages (ASP) files (.asp files). However, they can be invoked from other sources as well, such as an ISAPI application, another server component, and other OLE-compatible languages. Server components allow packaging and reuse of common dynamic features such as database access.

This section provides an overview of some of the tasks you can accomplish with the ActiveX server components included in ASP. For a fuller description of these components and a list of their properties and methods, refer to Component Reference.

Creating a Reference to an ActiveX Server Component

A single directive allows you to create a reference to an ActiveX server component. Once you have a reference to the component, you can call the methods of the component or set and read server component properties. The following script creates a reference to the BrowserType component:

<% Set bc = Server.CreateObject("MSWC.BrowserType") %> 

Retrieving Data from a Database

You can use the Database Access component to provide database access to your Web application. You can display the entire contents of a table, allow users to construct queries, and perform other database operations from Web pages. For examples and a description of the Database Access component, see Component Reference.

Displaying Advertisements on a Page

In your application, you might want to display advertisements for other companies and provide links to their sites. The Ad Rotator component makes this easy. You can keep a list of advertisements in a text file and the Ad Rotator component displays them as appropriate. The following script, for example, displays an ad when a user requests a page.

<% Set Ad = Server.CreateObject("MSWC.Adrotator") %> 
  <% Ad.GetAdvertisement("/ads/adrot.txt") %> 

One possible output from this example is the following HTML.

<A HREF="http://www.msn.com/isapi/adredir.dll?http://www.company.com/"> 
<IMG SRC="http://msnnt3web/ads/homepage/chlogo_lg.gif" 
ALT="Check out the new Technology Center" 
WIDTH=440 HEIGHT=60 BORDER=1></A> 

For more information about the Ad Rotator component, refer to ActiveX Server Component Reference.

Determining Browser Capability

Because of the variety of browsers and browser capabilities on the Web, you will often want to determine what capabilities a user’s browser has before sending content. You can use the Browser Capability component to do this. For more information, refer to ActiveX Server Component Reference.

Reading from and Writing to Files

The TextStream component allows you to read from and write to files on the server. The TextStream component is part of the FileSystem component. For more information about the TextStream component, refer to ActiveX Server Component Reference.

Managing Sequential Page Navigation

The NextLink component makes it easy for you to provide logical navigation through the pages in your application. Rather than maintaining URL references in a number of .asp pages, you can specify the sequential organization of pages in a single, easy-to-edit text file. The following example reads the link order from a text file and creates a table of contents on a single page.

<% Set NextLink=Server.CreateObject("MSWC.NextLink") %> 
<% count=NextLink.GetListCount("/Nextlink.txt") %> 
<% i=1 %> 
<UL> 
<% For i = 1 to count %> 
  <li><a href="<% =NextLink.GetNthUrl("/Nextlink.txt",i) %>"> 
  <% =NextLink.GetNthDescription("/Nextlink.txt",i) %></a> 
<% Next %> 

For more information about the NextLink component, refer to ActiveX Server Component Reference.


© 1996 Microsoft Corporation. All rights reserved.