๐ ASP โ Content Rotator โ Display Randomized Text or HTML in Classic ASP
๐งฒ Introduction โ What Is the ASP Content Rotator?
The ASP Content Rotator is a simple, classic ASP tool that allows developers to randomly rotate chunks of contentโlike quotes, ads, or tipsโon a webpage. Unlike the Ad Rotator (which is image-based), the Content Rotator focuses on text or HTML block rotation using a text-based configuration file.
๐ฏ In this guide, youโll learn:
- How the Classic ASP Content Rotator works
- How to format the content rotation file
- Embed randomized HTML/text content into your ASP pages
- Best practices and real output examples
๐ How It Works โ The .txt
Content File Format
The Content Rotator uses a special text file that separates each content block with a line starting with "%%"
.
๐ Sample rotate.txt
:
%%
<b>Tip:</b> Press CTRL+S to save your work regularly.
%%
<b>Fun Fact:</b> ASP stands for Active Server Pages.
%%
<b>Reminder:</b> Clear your browser cache weekly.
โ
Classic ASP Example โ Using ContentRotator
<%
Set obj = Server.CreateObject("MSWC.ContentRotator")
Dim result
result = obj.ChooseContent(Server.MapPath("rotate.txt"))
Response.Write result
%>
๐งช Output Example (Random):
<b>Fun Fact:</b> ASP stands for Active Server Pages.
๐ MSWC.ContentRotator
is a COM component built into Classic ASP/IIS.
๐ Where to Store the .txt
File
- Place it in a secure, read-accessible folder like
/includes/rotate.txt
- Use
Server.MapPath()
to convert the relative path to an absolute one
๐ HTML Integration โ Embed into Any Page
<div class="rotator">
<% =obj.ChooseContent(Server.MapPath("rotate.txt")) %>
</div>
๐ Rotate promotional content, quotes, customer testimonials, or announcements.
๐ How Rotation Works
- Random entry is chosen on every page load
- Entries are separated by
"%%"
markers - Only one block is selected at a time
๐ Best Practices for ASP Content Rotator
โ Do:
- Escape quotes (
"
) inside content or use single quotes ('
) - Use
Server.MapPath()
to avoid broken path errors - Limit content size in each block for faster rendering
โ Avoid:
- Mixing it with binary content (itโs for HTML/text only)
- Including script tags unless carefully managed
- Dynamically writing to the rotation file (causes conflicts)
๐ Summary โ Recap & Next Steps
The ASP Content Rotator is a great way to add variation to static content without JavaScript or a database. It’s ideal for random messages, tips, or notifications that enhance user engagement with minimal setup.
๐ Key Takeaways:
- Use
MSWC.ContentRotator
with arotate.txt
file - Separate content with
"%%"
to define entries - Display random text or HTML blocks on page load
โ๏ธ Real-world Use Cases:
- Daily tips, coding quotes, marketing slogans
- Testimonials and client feedback display
- Educational platforms for rotating practice questions
โ FAQs โ ASP Content Rotator
โ What format does the content file require?
โ
Each entry must be separated by a line containing only %%
.
โ Can I use HTML inside the rotation entries?
โ
Yes! You can add <b>
, <p>
, <a>
, and other HTML tags.
โ Does it rotate per session or per page load?
โ
It rotates per page load, not per session.
Share Now :