| Editorial Note: Since this article was published, technologies
have moved on, as they always do. ASP is now generally referred to as Classic
ASP. The preferred Microsoft web tecnology is now ASP.NET. Follow this
link for an updated article that shows
how to handle banners in ASP.NET. |
Your web site is receiving an ever-increasing amount of
traffic from users interested in your content. Now you'd like to capitalize
on the traffic and make some money from advertising. Due to the highly focused
nature of your site's content, you've even been able to get some companies to
give you banners to display.
Now what?
Basically, you need to be able to display banners on your
web pages, without having to manually edit every web page that comprises your
site. Additionally, you'd like to have a way to automatically rotate the banners,
and even control how often some of the banners display.
Using Active Server Pages (ASP), this can easily be accomplished.
ASP is a technology supported by Microsoft's Internet Information Server (IIS), one
of the most common web servers around.
ASP is a server-side technology, which means that programmers
include code in their web pages mixed in with HTML. The web server ensures that
the ASP code is executed on the server, before the HTML page is sent back to a
user's browser. When executed, the ASP code can write out HTML content, which
will be sent back to the browser as part of the HTML page. Thus, ASP code
can select a banner to be displayed and output the necessary HTML to display it.
Ad Rotator Component
One of the standard components provided by ASP is the Ad
Rotator. This component will display a different banner each time a web page is
displayed. The Ad Rotator depends on a configuration file, referred to as a
rotator schedule file, to specify the banners that will be displayed, as
well as any other information that is required.
When a banner is clicked on, the user is sent to a redirection
page. This page receives information about the click, including the specific banner
image that was clicked on and the destination URL.
This page is expected to record information about the
click-through, if desired, and then redirect the users to the expected web page.
This redirection will, of course, be entirely transparent to any users.
Rotator Schedule File
For each banner, the Ad Rotator needs to know the following
things:
- The location of the banner image.
- The destination to go to when the banner is clicked.
- The size (width and height) of the banner.
- The alternate text to be displayed if the user hovers
their mouse over the banner.
- How often the banner should be displayed.
This information is recorded in a configuration file known
as a rotator schedule file. A sample file is shown in Listing 1.
Listing 1: Rotator Schedule File
REDIRECT redirect.asp
WIDTH 468
HEIGHT 60
BORDER 0
*
http://www.yoursite.com/images/banner_468_60/banner001.gif http://www.microsoft.com
Go to the Microsoft Home Page
20
http://www.yoursite.com/images/banner_468_60/banner002.gif
http://www.oracle.com Learn About Oracle Database Products
10
|
The file begins with a global section that applies to all
banners listed in the file. The line with the asterisk ends the global section.
The REDIRECT field tells the Ad Rotator where to go to when the banner is clicked.
The WIDTH and HEIGHT fields define the size of the banner, while the BORDER
field indicates the width of the border that should be displayed around
the banner (with zero indicating no border at all).
This is followed by a series of lines describing banners that
will be displayed by the Ad Rotator. For each banner, the first line indicates
where the banner image can be found. The second line shows the destination URL
for the banner. The next line provides alternate text to be displayed if the
banner cannot be shown (i.e. - if a user has a text-only web browser or is
surfing with graphics turned off). Most browsers will also show this text
if the user simply hovers their mouse over the banner.
The final number shown for each banner is the relative weight,
which governs how often a banner will be shown in comparison to other banners in
the file. In the example, the weight of the first banner is twice that of the second
banner, so the Microsoft banner will be displayed twice as often.
Displaying a Banner Using the Ad Rotator
The code to display a banner is straightforward, as shown in
Listing 2. Simply create an instance of the Ad Rotator object. Then call
the GetAdvertisement method, passing in the location of the rotator schedule
file. The function returns the necessary HTML to display the banner, which
is then immediately written out and sent back to the user's browser.
This code could be added to every page that displays a banner.
More likely, though, an enterprising programmer would incorporate this code into
web pages via a server-side include.
Listing 2: Displaying a Banner
<%
Dim objAdrot
'---- Create the component
Set objAdrot = Server.CreateObject("MSWC.AdRotator")
'---- Get the ad from the rotator schedule file and write out the infor
Response.Write objAdrot.GetAdvertisement("/banners_468_60.txt")
'---- Destroy the object
Set objAdrot = nothing
%>
|
Handling the Redirection
The redirection file receives two parameters, the URL of
the destination and the name of the banner file. Generally, the second is not
used. Listing 3 shows the ASP code that redirects the user to the desired
destination.
The redirection file could, of course, do much more than this.
For example, it could store information about banner click-throughs in a
database.
Listing 3: Redirection File
<% Response.Redirect Request.QueryString("URL")
%>
|
Conclusion
Microsoft's Ad Rotator component, which is an integral part
of ASP, provides an easy way to add rotating banners to a web site. While the
component has limited functionality compared to sophisticated commercial
advertisement management systems, it nevertheless represents a free and
effective way to add advertising capabilities to web sites, particularly for
smaller businesses.
|