๐Ÿงฐ Common ASP References (Shared)
Estimated reading: 4 minutes 190 views

ASP โ€“ Ad Rotator (Shared with ASP.NET) โ€“ Display Rotating Banner Ads Easily

Introduction โ€“ What Is the ASP Ad Rotator?

The ASP Ad Rotator is a built-in feature that allows Classic ASP and ASP.NET pages to dynamically rotate banner ads. It works using a server-side XML-like text file containing ad definitions, and displays ads randomly or based on weight. Itโ€™s one of the earliest tools used for managing banner advertising in web applications.

In this guide, youโ€™ll learn:

  • How to use the AdRotator component in Classic ASP
  • Format and structure of the ad file (ad rotator text file)
  • Embed rotating ads into HTML pages
  • Differences between Classic ASP and ASP.NET usage

The Ad Rotator File โ€“ Format & Syntax

ASP Ad Rotator uses a text file similar to an .ini or .xml file with comma-separated values. Each line represents one ad.

Sample ads.txt

ImageURL, NavigateURL, AlternateText, Impressions, Keyword
/banner1.jpg, https://example.com/product1, Product 1, 50, Electronics
/banner2.jpg, https://example.com/product2, Product 2, 25, Gadgets
/banner3.jpg, https://example.com/product3, Product 3, 25, Deals

Fields:

  1. ImageURL โ€“ Relative or absolute URL to the banner image
  2. NavigateURL โ€“ Link user is sent to when they click the ad
  3. AlternateText โ€“ Tooltip or alt text for accessibility
  4. Impressions โ€“ Weighted percentage of ad display
  5. Keyword โ€“ Optional keyword filter (used in ASP.NET only)

Classic ASP Example โ€“ Display Rotating Ad

<!--#include virtual="/adrotator/AdRotator.inc"-->

<%
' Display random ad from ads.txt
AdRotator "/ads/ads.txt"
%>

The AdRotator function is defined in an included file such as AdRotator.inc or can be part of a custom function.


ASP.NET Equivalent โ€“ <asp:AdRotator>

In ASP.NET, the AdRotator is a server control:

<asp:AdRotator 
    ID="AdBanner" 
    runat="server" 
    AdvertisementFile="~/ads/ads.xml" 
    KeywordFilter="Electronics" />

Sample ads.xml (ASP.NET format)

<Advertisements>
  <Ad>
    <ImageUrl>~/images/banner1.jpg</ImageUrl>
    <NavigateUrl>https://example.com/product1</NavigateUrl>
    <AlternateText>Product 1</AlternateText>
    <Impressions>50</Impressions>
    <Keyword>Electronics</Keyword>
  </Ad>
  <Ad>
    <ImageUrl>~/images/banner2.jpg</ImageUrl>
    <NavigateUrl>https://example.com/product2</NavigateUrl>
    <AlternateText>Product 2</AlternateText>
    <Impressions>25</Impressions>
    <Keyword>Gadgets</Keyword>
  </Ad>
</Advertisements>

Output Example

If the ad rotator selects Product 1, the output HTML would look like:

<a href="https://example.com/product1">
  <img src="/images/banner1.jpg" alt="Product 1" />
</a>

Ad is randomly selected based on the impression weight.


How Rotation Works

  • Ads with higher Impressions are more likely to be shown.
  • If all ads have the same impression weight, each is equally likely.
  • Classic ASP reads from .txt
  • ASP.NET reads from .xml (with support for filters)

Best Practices for Ad Rotator

Do:

  • Store ad file in a secure folder like /ads/
  • Use relative paths for portability
  • Test ad weights by adjusting Impressions values
  • Sanitize all ad content if dynamically generated

Avoid:

  • Serving broken image links or invalid URLs
  • Skipping AlternateText (affects accessibility and SEO)
  • Hardcoding ad HTML instead of using the rotator for maintainability

Summary โ€“ Recap & Next Steps

The ASP Ad Rotator simplifies rotating ad banners using a centralized text (Classic ASP) or XML (ASP.NET) ad file. It ensures equal or weighted exposure of ads, and integrates easily into static or dynamic websites.

Key Takeaways:

  • Use .txt for Classic ASP and .xml for ASP.NET
  • AdRotator randomizes ads based on defined weights
  • Easy to maintain and update without changing HTML

Real-world Use Cases:

  • Rotating banner ads on blogs or CMS
  • Internal announcements in intranet portals
  • Seasonal promotions on e-commerce sites

FAQs โ€“ ASP Ad Rotator


Is Ad Rotator still supported in ASP.NET?
Yes, though itโ€™s considered legacy. <asp:AdRotator> works in Web Forms, but not in Razor Pages or MVC.


Can I rotate HTML snippets instead of images?
Not directly with Ad Rotator. For full HTML ad rotation, use custom ASP logic or JavaScript.


How does Impressions affect ad rotation?
Higher Impressions values increase the chance of that ad appearing. Itโ€™s relative, not fixed.


Share Now :
Share

๐ŸŽž๏ธ ASP โ€“ Ad Rotator (shared with ASP.NET)

Or Copy Link

CONTENTS
Scroll to Top