asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Dynamic Banner Administration
By Wayne Berry
Rating: 3.2 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    This Issue

    Many sites that are content specific depend on banner advertisement for revenue. Such is the case for 15 Seconds. A banner is displayed at the top of the page for every page viewed. Clients usually buy a set number of banner impressions and these impressions are rotated amongst all the clients over a period of time. In order to do this there must be a dynamic quality to the banners. In other words, the banner to display is not determined until that page is requested.

    With an Active Server page this is an easy task. Active Server Pages are dynamic and there are many components that handle the task of banner rotation. A simple one comes free with the Internet Information Server, and more complicated rotation schedules can be done with Site Server and other third party components. This article is not about how to implement these components within your Active Server pages, since this is a fairly easy task.

    This article will describe how to implement a banner rotation scenario where the pages served are static, i.e. .htm, and do not have the flexibility to call components. The task is to dynamically serve banners and statically serve pages. This is the opposite of the scenario for banner rotation components, which statically serve banners and dynamically serve pages.

    One Trick

    There is only one trick here and once you know it the rest is pretty straightforward. Internet Explorer and Netscape allow you to refer to an Active Server Page within an image tag. Example 1 demonstrates the HTML to be inserted in the static page.

    Example 1 : HTML Banner Reference

    
    < IMG SRC="http://www.myserver.com/ServeBanner.asp">
    
    

    Once you have referred to a dynamic Active Server page with the static page, you need to build an Active Server page to return an image, in this case a banner. Example 2 shows the code to use for servebanner.asp which is called in Example 1.

    Example 2 : ServeBanner.asp Source

    
    <%
    Response.Redirect("http://www.myserver.com/banner.gif")
    %>
    
    

    These two pages combined will allow you to display to the user a banner as if you referred directly to the banner image instead of an Active Server page. In order to do banner rotation all you have to do is expand Example 2 so different images come up every time ServeBanner.asp is called.

    Adding the Element of Rotation.

    With this technique the dynamic aspect of the banner rotation is controlled within the Active Server page that the IMG tag is referring to. In order to randomly rotate the banners you will need to change ServerBanner.asp to choose a different banner each time that it is called. Example 3 shows how to do this.

    Example 3 : Rotating Banners

    
    <%
    
    Dim	Array(2)
    
    ' Initialize the VBScript Random
    ' Number Generator
    Randomize
    
    Array(1)="http://www.myserver.com/banner1.gif"
    Array(2)="http://www.myserver.com/banner2.gif"
    
    upperbound=UBound(Array)
    lowerbound=1	
    lRandom = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
    
    Response.Redirect(Array(lRandom))
    
    %>
    
    

    Notice that you will have to initialize the array for as many banners as are available and you will have to assign a banner to each element of the array.

    An Extra Benefit

    An obvious benefit to this type of banner rotation is that fact that you don't have to serve Active Server pages in order to have rotating banners. If the only dynamic aspect of your Active Server page is to rotate banners you will want to change it to use this banner rotation technique, since it will reduce the stress on your server.

    It might not be so obvious that the static pages no longer need to reside on your machine to rotate banners. For example, you could give the HTML in Example 1 to a site that you were advertising on, and when they serve there pages with your HTML your server will rotate the banners for their site. This allows you control of what banners are presented to their readers. The site that was serving the static pages could even be a different operating system, such as UNIX.

    Clicking on the Banner

    So far we have demonstrated how to rotate banners, but not how to activate those banners so that you can click on the banner to go to another site. With one banner in the rotation this is a straightforward process, you just point the anchor tag to the site which the banner represents. However when you have multiple banners in the rotation it becomes more difficult. The problem is that a random banner is served every time you request a page, however the anchor tag on that page does not change, since the page is static.

    To solve this problem the anchor tag needs to reference an Active Server page that can determine what banner was being displayed so that it can redirect the browser to that page. Example 4 shows what the HTML will look like to activate the banners in this banner rotation technique.

    Example 4 : Activating the Banners

    
    < A HREF=" http://www.myserver.com/BannerClick.asp">
    < IMG SRC="http://www.myserver.com/ServeBanner.asp">
    < /A>
    
    

    BannerClick.asp now has the responsibility of redirecting to the correct location. However, currently there is no way for BannerClick.asp to know which banner is being displayed to the user. In order to determine this, ServeBanner.asp must tell the browser which banner it is going to display so that if the user clicks through BannerClick.asp can ask the browser what banner was being shown. One way to do this is to use cookies?. Example 5 shows how to modify ServeBanner.asp so that it sets a cookie every time a banner is served.

    Example 5 : Rotating Banners with Cookies

    
    <%
    
    Dim	Array(2)
    
    ' Initialize the VBScript Random
    ' Number Generator
    Randomize
    
    Array(1)="http://www.myserver.com/banner1.gif"
    Array(2)="http://www.myserver.com/banner2.gif"
    
    upperbound=UBound(Array)
    lowerbound=1	
    lRandom = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
    
    Response.Cookies("BannerId")=lRandom
    Response.Redirect(Array(lRandom))
    
    %>
    
    

    Once ServeBanner.asp is coded so that it issues a cookie for each request, and that cookie is the banner identifier in the array, we can program ClickBanner.asp so that it reads the cookie and redirects to the correct location. Example 6 shows how to implement ClickBanner.asp.

    Example 6 : ClickBanner.asp

    
    <%
    
    Dim	Array(2)
    
    lBannerId  = Request.Cookies("BannerId")
    
    Array(1)="http://www.client1.com"
    Array(2)= "http://www.client2.com"
    
    Response.Redirect(Array(lBannerId))
    
    %>
    
    

    Notice that the array is used differently in ServeBanner.asp then it is used in ClickBanner.asp. In ServeBanner.asp the array referenced banner graphics, in ClickBanner.asp the array references the location to go to when the banners is clicked. Since the index in the array is used in both locations the array must be populated so that for every index the banner image matches the location.

    Handling Netscape

    The Netscape browser has a bug in it that needs to be avoided when rotating banners using this technique. If you do not specify the size of an image in HTML Netscape queries the image itself to determine the size. This is a feature that both Netscape and Internet Explorer have. However, Netscape queries the first response to the image call for the size. Using this technique the first response is a set of headers that are suppose to redirect the browser to the real graphic. When Netscape queries the headers for the image size it fails since the response its not an image. In order to avoid this problem you will need to specify the banner image size in the HTML. Example 7 shows Example 4 rewritten to specify the image size.

    Example 7 : Setting the Image Size

    
    < A HREF=" http://www.myserver.com/BannerClick.asp">
    < IMG WIDTH=468 HEIGHT=60 SRC="http://www.myserver.com/ServeBanner.asp">
    < /A>
    
    
    Because of this bug there is no way to serve banners that are of varying sizes, since the size is specified in a static page which does not change with the banner that is served.

    Beyond

    The next step in creating your own banner rotation application is to put the banner arrays in a database and to query the database every time a page is requested. This would allow you the flexibility to change the banners using another set of Active Server pages which administers the database.

    You could also implement a better rotation schema that would have a daily cap on the number of impressions served and a maximum number of impressions to serve. You might also want to implement a default banner, so that when the maximums are met there is something to rotate.

    Another interesting addition would be the logging of the number of banners served and the number of click throughs per banner. Then creating a set of Active Server pages to display the statistics in a variety of forms.

    However, before you go off and build yourself a database, and implement complicated banner rotation algorithms you might want to consider buying a product that already does what you want. Banager (http://www.banager.com) is an Active Server page application that is implemented using the techniques discussed in this article. However, Banager has statistical pages, database logging and banner rotation algorithms built in. In my opinion it is well worth the cost.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Other Articles
    Sep 29, 2005 - Migrating to a Load Balanced IIS 6 Environment
    Migration to IIS 6 can present itself as a daunting challenge. Depending on your existing hosting configuration, the process can number in hours, days, or even weeks. Careful planning and research is integral to achieve a successful migration.
    [Read This Article]  [Top]
    Apr 18, 2003 - IIS 6.0: Lessons in Trustworthy Computing
    Microsoft's Trustworthy Computing initiative significantly changed the way in which Microsoft builds and designs software. In this article, Jeff Gonzalez explores some of the new options and architecture in Internet Information Services 6.0.
    [Read This Article]  [Top]
    Mar 25, 2002 - Moving IIS To A Different Server - Part 2
    Brien Posey evaluates two additional methods for migrating a Web server and it settings, backup/restore and ghosting.
    [Read This Article]  [Top]
    Feb 27, 2002 - Moving Your IIS Server to a New Server - Part 1
    Upgrading your server? Brien Posey takes a look at the process and pitfalls of migrating IIS to a completely different server.
    [Read This Article]  [Top]
    Jan 23, 2002 - Troubleshooting IIS Access Problems
    Spending countless hours developing a Web site only to discover that no one can access it is frustrating. This article guides you through the process of troubleshooting Web-site access problems.
    [Read This Article]  [Top]
    Jan 18, 2002 - Running IIS on Windows XP Home Edition?
    Members of the 15Seconds discussion list may have found a way to run IIS on Windows XP Home Edition, so developers can run ASP pages. Attempt at your own risk!
    [Read This Article]  [Top]
    Dec 27, 2001 - Working With IIS Packet Filtering
    Brien Posey discusses IP packet filtering and other ways in which to control access through IIS.
    [Read This Article]  [Top]
    Oct 30, 2001 - Protecting Your IIS Server and Web Application
    Internet viruses such as Code Red and Nimbda have brought down numerous IIS Web servers recently. Fortify and defend your system with this comprehensive strategy authored by 30-year industry veteran, Andrew Novick.
    [Read This Article]  [Top]
    Oct 16, 2001 - Implementing an E-mail Content Filter Using CDO
    Stop SPAM from sliding through your e-mail system. George Walker shows how to create an e-mail content filter for the Windows 2000 SMTP service using Microsoft Collaboration Data Objects.
    [Read This Article]  [Top]
    Feb 10, 2000 - Creating Dynamic JavaScript with ASP and Databases
    Travis Giggy demonstrates how to put ASP tags inside of JavaScript blocks so developers can fit large amounts of data into one form on a single page. He offers an overview of things that can be done with dynamic JavaScript with ASP and data queries.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers