This section provides an overview of some of the tasks you can accomplish with the ActiveX server components included with Active Server Pages (ASP). For a complete description of these components and a list of their properties and methods, refer to Component Reference.
ActiveX server components, formerly known as Automation servers, are designed to run on your Web server as part of a Web-based application. Components package common dynamic features, such as database access, so that you do not have to create and recreate these features.
Components are typically invoked from .asp files. However, you can invoke components from other sources as well, such as an ISAPI application, another server component, and other OLE-compatible languages.
Active Server Pages (ASP) includes five ActiveX server components:
You can create an instance of an ActiveX server component with a single statement. Once you have created an instance of a component, you can use the methods associated with that component, or set and read the components properties.
The following script uses the Server.CreateObject method to create an instance of the Browser Capabilities component and assigns it to the variable bc:
<% Set bc = Server.CreateObject("MSWC.BrowserType") %>
You can also use the <OBJECT> tag to create a component instance. This example creates an instance of the Ad Rotator Component:
<OBJECT RUNAT=Server ID=MyAd PROGID="MSWC.AdRotator"></OBJECT>
Note Typically, you use the extended <OBJECT> tag in the Global.asa file to create session-scope or application-scope component instances. For more information, see Setting Component Scope.
You can use the Database Access component to provide access to a database from within your Web application. You can then 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, refer to Component Reference.
You can use the Ad Rotator component to display and alternate a series of images, as well as to provide a link from the displayed image to another URL. You keep a list of advertisements in a text file; the Ad Rotator component displays them according to the statements in your data file. 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") %>
Such a script might produce the following HTML.
<A HREF="http://www.msn.com/scripts/adredir.asp?url=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 Component Reference.
Because of the variety of browsers and browser capabilities on the Web, you may want to tailor the content you send to a browser based on the browser's capabilities. You can use the Browser Capability component to do this. For more information, refer to Component Reference.
The Content Linking component makes it easy for you to provide logical navigation through the .asp files in an application. Rather than maintaining URL references in a number of .asp files, you can specify the sequential organization of .asp files 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("/Vroot/Nextlink.txt")
%>
<UL>
<% For i = 1 to count %>
<li><a href="<%=NextLink.GetNthUrl("/Vroot/Nextlink.txt",i) %>">
<%=NextLink.GetNthDescription("/Vroot/Nextlink.txt",i) %></a>
<% Next %>
For more information about the Content Linking component, refer to Component Reference.