Behind the Scenes

This sample uses three files:

- RandomAd.asp displays the randomly selected advertisement.
- RandomAd.txt defines which advertisements to use.
- AdRedir.asp redirects the user after an ad is chosen.

RandomAd.asp uses just two lines of script to display the advertisement. The first line creates the object reference to the AdRotator component and the second line gets information from the RandomAd.txt file to display the ad:

<%Set ad = Server.CreateObject("MSWC.AdRotator")%>
<%= ad.GetAdvertisement("RandomAd.txt") %>

RandomAd.txt is used as the rotator schedule file. The rotator schedule file contains information that the Advertisement Rotator component uses to manage and display the various advertisement images. In it, you specify the details for the advertisements, such as the size of the advertisement space, the image files to use, and the percentage of time that each file should be displayed.

The rotator schedule file has two sections: * The first section sets parameters that apply to all advertisement images in the rotation schedule. * The second section specifies file and location information for each individual advertisement and the weight of display time that each advertisement should receive. The weight is a number between 0 and 4,294,967,295 that indicates the relative weight of the advertisement.

For example, if a rotator schedule file contains three ads with weights set to 2, 3, and 5, the first advertisement is displayed 20 percent of the time, the second 30 percent of the time, and the third 50 percent of the time.

A line containing only an asterisk separates the two sections (*). Below is a portion of the RandomAd.txt file that shows one advertisement entry:

REDIRECT AdRedir.asp
WIDTH 468
HEIGHT 60
BORDER 1
*
../images/rollover.gif
http://www.microsoft.com/frontpage
Free Beta Copy of Microsoft FrontPage 98
2

AdRedir.asp redirects users to the appropriate URL after they have clicked on the advertisement.

<%
If Request.QueryString("url") <> "" Then
Response.Redirect(Request.QueryString("url"))
End If
%>

can also include script in the redirection file to count the number of users that have clicked on a particular advertisement and save this information to a file on the server.