When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
Related Web Technologies
User Tips!
Coding Tips

Sample Chapters
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
Print this page.
Published: Wednesday, January 03, 2001

Developing a Customizable Banner Rotation System

By Peter McMahon

To Learn More About Banner Rotation Systems...
This article presents a couple ways to build a banner rotation system on your Web site. There are, however, many ways to accomplish this! To read articles on the bevy of techniques that can be used to create a banner rotation system, be sure to check out the: Banner Rotation Article Index!

- continued -

ALSO! Part 2 of this article is up and read: Extending the Customizable Banner Rotation System!

One of the most popular forms of advertising on the Internet are rotating banner advertisements. Using a banner rotation system, rather than a static system, you can sell many more banner ads for a smaller price. Another major advantage of using a banner rotation system is that you do not need to manually edit each page once a customer's contract has expired or a new contract begins. The system can also be spanned over multiple pages (and sites, so long as such sites reside on the same Web server).

To develop a customizable system we need to, as the saying goes, "look back to look forward." For starters, we should examine those tools that we are currently provided with to see what we can improve and innovate on. We'll start with an examination of\ Microsoft's solution, the Ad Rotator (To learn more about the Ad Rotator, be sure to read: Using the Ad Rotator!).

The Microsoft Solution: The Ad Rotator
Microsoft bundles their Ad Rotator component with IIS. This COM component provides functionality to load banners from a text file with the banner definitions, including the alternate text, image size and image location. The component only has a few properties and one method. These are outlined below, with a brief description of their usage and functionality, in the table below:

Ad Rotator Properties
BorderThis specifies the value of the BORDER attribute of the image tag that will be displayed
ClickableThis specifies whether the banner is a link or not
TargetFrameThis specifies the TARGET attribute of the ANCHOR tag (if applicable)

Ad Rotator Method
GetAdvertisementThis method is passed the location of the banner definition file as a parameter. It writes the image tag and accompanying anchor tag, if applicable.

The banner definition file takes the following form:

WIDTH integer
HEIGHT integer
BORDER border
alternate text

The first line, REDIRECT url, refers to the page that the produced anchor tag must link to and pass the banner's link URL to as a querysting. This is because the Ad Rotator component does not produce a link directly to the site, but rather to an ASP page that you must develop, which can simply redirect to the URL passed in the querystring, or perform logging operations.

The WIDTH parameter specifies the value to be inputted into the WIDTH attribute of the produced image tag, in pixels. The HEIGHT parameter specifies the value to be inputted into the HEIGHT attribute of the produced image tag, in pixels. The BORDER parameter specifies the value to be inputted into the BORDER attribute of the produced image tag, in pixels. The asterisk (*) indicates the start of the actual banner definitions. imageURL is the location of the banner file (for example, http://www.somesite.com/images/banner_large.gif). linkURL is the page/site that the banner should link to (eg. http://www.somesite.com). alternate text is the text that will be placed in the ALT attribute of the image text (eg. "Come see Somesite's services!"). impressions is the ratio of hits that the banner should receive. It has limit of 10000. This value is relative to the amount of other banners, and their respective impression weightings. If there are three banners defined, with weightings 2, 3 and 5, the first banner will be displayed 20% of the time, the second 30% and the third 50%.

The first thing that you need to do is create the banner definitions file (call it adrot.txt if you intend to copy-and-paste the code and create the system while you read). I firmly believe in learning through examples, so below is a sample banner definition file with hypothetical banners and links:

REDIRECT redirect.asp
Visit Somesite Now!
Come on over to Anothersite!
Yetanothersite.com  your online widget retailer

In the above example, somesite.com and anothersite.com's banners will be displayed 40% of the time each and yetanothersite.com's banner will be displayed 20% of the time. Now we need to create the ASP to insert the above banner. This code will be added to each page that will have a banner displayed on it. It would probably be more suitable to place it in an include file, to make administration easier, especially if you need to change something, but here it is:

  Dim objAd
  'Create the component
  Set objAd = Server.CreateObject("MSWC.AdRotator")
  'Get the ad from adrot.txt and write the link
  Response.Write objAd.GetAdvertisement("adrot.txt")

  'Destroy the object
  Set objAd = Nothing

This code simply generates the link and image tag and writes it to the page. You then need to create the redirection file which will redirect the user to the link in the linkURL section of the banner definition file, as well as perform click-thru logging functions, if required. For this example, I will just perform the redirection. (If you are coding this app as we go along, call this file redirect.asp)

<% Response.Redirect Request.QueryString("URL") %>

That's it! All the hard work of randomly selecting a banner ad is done for you by the component. (For those of you who don't want to copy-and-paste the above code into the respective files, a download for this sample is provided at the bottom of the article.) However, this ease-of-use, as is usually the case, comes with the price of inflexibility. With this system in place, how to you monitor banner impressions (which banner advertisers often demand)? And how do you handle different categories of banners for different parts of a site? And what if a client deposits his payment and wants his banner running NOW and you're on a week holiday half a world away from your Web server? (My solution only helps if you can get to an Internet Cafe, but if you couldn't you wouldn't have gotten you're client's e-mail informing you to make the change anyway) If you've got 5,000 clients advertising, administering that text file is going to become really tedious. The solution an architecture designed to be flexible and scalable to large volumes of data a database.

Now that we've looked at how to create a simple banner rotation system using Microsoft's Ad Rotator component, it's time that we look at a more customizable, powerful solution: a custom, data-driven banner rotation application. In Part 2 we'll examine one way that one can go about creating such a system!

  • Read Part 2!

  • ASP.NET [1.x] [2.0] | ASPFAQs.com | Advertise | Feedback | Author an Article