๐๏ธ 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:
- ImageURL โ Relative or absolute URL to the banner image
- NavigateURL โ Link user is sent to when they click the ad
- AlternateText โ Tooltip or alt text for accessibility
- Impressions โ Weighted percentage of ad display
- 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 :