Rotating Advertisements with the AdRotator Component in ASP

Last Updated: Nov 07, 2025
5 min read
Legacy Archive
Legacy Guidance: This article preserves historical web development content. For modern .NET 8+ best practices, visit our Tutorials section.

Introduction

Banner ads have become a standard part of the web experience. Microsoft simplifies the process of adding randomly rotating banners to your site with the AdRotator component, making it easy to manage multiple advertisements without manual intervention.

Components Required for Ad Rotation

You'll need three components to implement the AdRotator. First is the rotator schedule file, which tells the AdRotator what images to use and where to link them. Second is an ASP page that handles redirecting users to the appropriate URL. Third is the actual page that displays the advertisements.

Creating the Rotator Schedule File

Start by creating a rotator schedule file with the following structure:

schedule.txt
REDIRECT redirect.asp
WIDTH 440
HEIGHT 60
BORDER 1
*
images/banner1.gif
http://www.site1.com
Visit Site 1
20
images/banner2.gif
http://www.site2.com
Visit Site 2
30
images/banner3.gif
http://www.site3.com
Visit Site 3
50

Understanding the Configuration Options

The first section of the file contains global settings that affect every banner. The REDIRECT line specifies the URL of an ASP page or DLL that handles redirecting users to the correct destination. This gives you control over what happens when someone clicks a banner, allowing you to open new windows or track clicks for statistics. You can use either a full URL or a relative path. If you want the current page to handle redirection, simply omit this line.

The WIDTH option specifies the banner width in pixels (default is 440). The HEIGHT option sets the banner height in pixels (default is 60). The BORDER option defines the thickness of the border drawn around the image in pixels (default is 1). All these settings are optional.

The asterisk on its own line is critical because it marks where the configuration section ends and the advertisement definitions begin.

Defining Individual Advertisements

After the asterisk, you'll define each advertisement using four lines:

  • Image URL points to the graphic file for this ad. You can use either a relative or full URL.
  • Homepage URL is where users go when they click the banner. This URL gets passed to the redirect page. If there's no destination, use a hyphen (-).
  • Alt Text displays when users have graphics disabled, before the image loads, or when hovering over the image with their mouse.
  • Weight is a number between 0 and 10,000 that controls how often this ad appears relative to others. If all ads have equal weight, they'll appear with equal frequency. For example, with three ads weighted at 10, 20, and 20, the first ad appears 20% of the time while the other two each appear 40% of the time.

Implementing the AdRotator on Your Page

Here's how to add the AdRotator component to your ASP page:

Display Page
<%
Set objAdRotator = Server.CreateObject("MSWC.AdRotator")
Response.Write objAdRotator.GetAdvertisement("schedule.txt")
%>

This code creates an instance of the AdRotator component and displays a random advertisement from your schedule file.

Creating the Redirect Handler

Build a redirect page to track clicks and control navigation:

redirect.asp
<%
strURL = Request.QueryString("url")
strImage = Request.QueryString("image")

' Log the click for statistics
' Your tracking code here

' Redirect to the destination
Response.Redirect(strURL)
%>

The redirect page receives the destination URL and image path as query string parameters, letting you log clicks before sending users to their destination.

Advanced Implementation Example

Here's a complete example with custom redirect handling:

Complete Implementation
<!-- Display page with AdRotator -->
<%
Set objAdRotator = Server.CreateObject("MSWC.AdRotator")
strSchedule = Server.MapPath("ads/schedule.txt")
Response.Write objAdRotator.GetAdvertisement(strSchedule)
%>

Conclusion

The AdRotator component provides an efficient way to manage rotating advertisements on your website while giving you flexibility through the weighting system to prioritize certain ads over others. By implementing a redirect handler, you gain complete control over click tracking and user navigation, making it an essential tool for any Classic ASP website with advertising needs.

Quick FAQ

How do I make certain advertisements appear more frequently than others?

Use the Weight parameter in your schedule file. An ad with a weight of 50 will appear roughly twice as often as an ad with a weight of 25. The component calculates display probability by dividing each ad's weight by the sum of all weights. This lets you give premium placement to high-value advertisers without creating duplicate entries.

Can I track which advertisements users click on?

Yes, you'll implement a redirect page specified in the REDIRECT line of your schedule file. When users click an ad, they're sent to this page with the destination URL and image path as query string parameters. You can log this information to a database or file before redirecting to the actual destination, giving you complete click tracking capabilities.

What happens if I omit the REDIRECT line in my schedule file?

If you omit the REDIRECT line, clicking on an advertisement will navigate directly to the homepage URL specified for that ad without any intermediate processing. This is suitable when you don't need click tracking or custom redirect behavior, providing a simpler implementation for basic ad rotation needs.

Back to Articles