Chapter 57: ASP AdRotator Component
ASP AdRotator Component.
This is the exact lesson that appears in the W3Schools Classic ASP tutorial, and it was one of the most exciting things for beginners in 1998–2005 because it let you show rotating banner ads on your website with almost no coding.
I will explain it like your favorite teacher who actually used AdRotator on real client sites back in the early 2000s (when banner ads were the main way small websites made money) — slowly, clearly, with real working examples, good habits, common mistakes, security notes, and the exact patterns you would see in legacy Indian small-business, portal, and community sites that still run this way in 2026.
1. What is the AdRotator Component?
AdRotator is a built-in ActiveX Server Component that comes with IIS and Classic ASP.
Its only job is to:
- Read a simple text file (usually called ads.txt or adrotator.txt) that lists banner ads
- Pick one ad randomly (or weighted) each time the page loads
- Automatically generate the correct <a href=”…”><img src=”…”></a> HTML tag
- Rotate ads fairly over time (keeps track of impressions internally)
It was extremely popular because:
- Banner advertising was the main monetization model in the late 90s / early 2000s
- You didn’t need JavaScript or external ad networks
- It worked perfectly with Classic ASP pages
- Very easy to set up and manage (just edit a text file)
Even in 2026, some very old Indian classifieds portals, community sites, and internal company portals still use AdRotator for simple internal banner rotation or legacy ad deals.
2. How AdRotator Works — The Three Main Pieces
You need three things to use AdRotator:
- The AdRotator component itself (already installed on IIS)
- A schedule file (text file with ad list — usually called ads.txt)
- The <object> tag on your .asp page to place the rotating ad
Step 1: The Schedule File (ads.txt) — The Heart of AdRotator
This is a plain text file (usually in the root or /ads folder). Format is very strict — every 4 lines = one ad entry.
Example ads.txt:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
REDIRECT redirect.asp WIDTH 468 HEIGHT 60 BORDER 0 * http://example.com/banners/ad1.gif http://example.com/click.php?id=1 468 60 Company 1 Banner 10 http://example.com/banners/ad2.jpg http://example.com/click.php?id=2 468 60 Company 2 Banner 30 http://example.com/banners/ad3.gif http://example.com/click.php?id=3 468 60 Company 3 Banner 20 |
Line-by-line explanation:
- REDIRECT redirect.asp — optional — if present, all clicks go through this page (for tracking)
- WIDTH 468 — banner width (global for all ads)
- HEIGHT 60 — banner height
- BORDER 0 — border thickness (usually 0)
- * — separator between global settings and first ad
- Image URL
- Click-through URL (where user goes when clicking)
- Width (per ad — can override global)
- Height
- Alternate text (tooltip)
- Weight / priority (higher = more often shown)
→ Total weight = 10 + 30 + 20 = 60 → Ad 1 shown ~17% of time, Ad 2 ~50%, Ad 3 ~33%
3. Step 2: Place AdRotator on Your Page
|
0 1 2 3 4 5 6 |
<%@ Language=VBScript %> <% Option Explicit %> <!DOCTYPE html> <html> <body> <h1>My Website</h1> <!-- AdRotator component --> <object runat="server" id="ad" classid="clsid:0006F400-0000-0000-C000-000000000046"> <param name="TargetFrame" value="_blank"> </object> <% ' Tell AdRotator which schedule file to use ad.GetAdvertisement(Server.MapPath("ads.txt")) %> |
Key points:
- The <object> tag is required — this is how you instantiate the COM component
- ad.GetAdvertisement(path) — tells it which ads.txt file to read
- TargetFrame=”_blank” — opens ad link in new tab (optional)
4. Step 3: The Redirect Page (for Tracking Clicks — Very Common)
File: redirect.asp
|
0 1 2 3 4 5 6 |
<%@ Language=VBScript %> <% Option Explicit %> <% Dim url url = Request.QueryString("url") ' Log the click (real code would save to database) ' Response.Write "Click logged for: " & Server.HTMLEncode(url) ' Redirect to actual ad destination If url <> "" Then Response.Redirect url Else Response.Redirect "default.asp" End If %> |
→ All ad clicks go through redirect.asp?url=… → you can log impressions/clicks before redirecting.
5. Security & Best Practice Warnings (Critical in 2026)
- Never let users control the schedule file path — hard-code Server.MapPath(“ads/ads.txt”)
- Never allow write access to the ads.txt folder — classic ASP sites were hacked via file upload + overwriting ad files
- Use Server.HTMLEncode if you ever display ad info from the file
- Disable FSO write access to web folders — many hacks used FSO + AdRotator folders
- Log clicks/redirects — otherwise you cannot track ad performance
- In 2026 legacy code → still used for internal banners or old ad deals, but very risky without strict permissions
6. Teacher Summary – ASP AdRotator Component in Classic ASP
ASP AdRotator is:
- A built-in COM component (clsid:…) that rotates banner ads
- Reads a simple text schedule file (ads.txt) with ad list + weights
- Automatically generates <a><img> HTML
- Supports REDIRECT page for click tracking
- Global settings: WIDTH, HEIGHT, BORDER
- Per-ad settings: image URL, click URL, alternate text, weight
- Used with <object runat=”server” classid=”…”> + ad.GetAdvertisement(path)
- Very popular 1998–2005 for banner ads on small sites
- Still alive in many legacy Indian portals, community sites, and internal dashboards
This is how millions of Classic ASP sites showed rotating banners and earned ad revenue in the early 2000s — and many legacy systems still use exactly this AdRotator pattern in 2026.
Next class?
- Want a full example with click logging + database tracking?
- Or how to weight ads differently and test rotation?
- Or compare Classic ASP AdRotator vs modern banner rotation (Google Ad Manager, etc.)?
- Or move to the next W3Schools topic (ASP Content Linking or ASP Content Rotator)?
Just tell me — I’m here! 🚀🇮🇳 Keep learning strong, Webliance! 😊
