๐งฐ Common ASP References โ VBScript, Server Objects, File APIs & Helpers
๐งฒ Introduction โ Build Efficient Classic ASP Apps with Reusable Helpers
Classic ASP comes equipped with a powerful set of built-in functions, objects, and APIs that make dynamic web development possible. From handling file systems and errors to rotating ads and detecting browsers, these shared references form the backbone of many classic web applications.
๐ฏ In this guide, youโll learn:
- Frequently used VBScript functions and keywords in ASP
- How to use
Request
,Response
, andServer
objects - How to manage files using the FileSystemObject API
- How to handle errors and work with dictionaries
- How to rotate content and ads dynamically
๐ Topics Covered
๐น Topic | ๐ Description |
---|---|
๐ ASP โ VB Functions | Commonly used VBScript functions for string, math, and date handling |
๐๏ธ ASP โ VB Keywords | Reserved words and syntax used in Classic ASP scripting |
๐ค ASP โ Response / Request | Read inputs and send output to browser |
๐ก ASP โ Server Object | Access file system, components, pathing, and encoding |
โ ASP โ Error Handling | Use On Error Resume Next and Err object |
๐ ASP โ File System API (Files/Folders) | Read, write, delete files or folders on the server |
๐ ASP โ File System API (Drive/TextStream) | Inspect drives, read/write text files |
๐งพ ASP โ Dictionary Object | Store key-value pairs in memory like a hashtable |
๐๏ธ ASP โ Ad Rotator | Rotate banner ads from XML or text file |
๐ง ASP โ BrowserCap | Detect browser type and capabilities |
๐ ASP โ Content Linking | Create navigable, linked content dynamically |
๐ ASP โ Content Rotator | Show different text/images on each page load |
๐ ASP โ VB Functions
Commonly used VBScript functions in Classic ASP:
Function | Use Case |
---|---|
Len() | Get string length |
Trim() | Remove extra spaces |
Now() | Current date and time |
DateAdd() | Add intervals to dates |
UCase() | Convert string to uppercase |
IsEmpty() | Check if variable is uninitialized |
Example:
<%
Response.Write UCase("hello")
%>
๐๏ธ ASP โ VB Keywords
Key reserved words in VBScript for control flow and logic:
If
,Then
,Else
,End If
Select Case
,Case
For
,Next
,Do
,While
,Loop
Function
,Sub
,Call
Dim
,Set
,Const
โ Must avoid using them as variable names.
๐ค ASP โ Request / Response Objects
๐น Read Input:
name = Request.Form("name")
๐น Write Output:
Response.Write "Welcome " & name
โ Response can also handle headers:
Response.AddHeader "Content-Type", "text/plain"
๐ก ASP โ Server Object
Access server resources:
Set fs = Server.CreateObject("Scripting.FileSystemObject")
path = Server.MapPath("data.txt")
encoded = Server.HTMLEncode("<b>bold</b>")
โ
CreateObject
, MapPath
, URLEncode
, HTMLEncode
are commonly used.
โ ASP โ Error Handling
On Error Resume Next
Set conn = Nothing
If Err.Number <> 0 Then
Response.Write "Error: " & Err.Description
Err.Clear
End If
โ Always clear the error after handling it.
๐ ASP โ File System API (FileSystemObject)
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set file = fs.OpenTextFile(Server.MapPath("data.txt"), 1)
text = file.ReadAll
file.Close
โ File Modes:
1
= Read2
= Write8
= Append
๐ ASP โ File System API (Drive/TextStream)
Set d = fs.GetDrive("C:")
Response.Write "Free space: " & d.FreeSpace
Set txt = fs.CreateTextFile(Server.MapPath("log.txt"), True)
txt.WriteLine "Log entry"
txt.Close
โ Can inspect drives and log diagnostics.
๐งพ ASP โ Dictionary Object
Set dict = Server.CreateObject("Scripting.Dictionary")
dict.Add "name", "Alice"
Response.Write dict.Item("name")
โ
Use .Exists
, .Remove
, .RemoveAll
for management.
๐๏ธ ASP โ Ad Rotator
<!--#include file="adrotator.inc"-->
<%
Randomize
DisplayAd "ads.txt"
%>
โ
ads.txt
should list banners with descriptions and links.
๐ง ASP โ BrowserCap
browser = Request.ServerVariables("HTTP_USER_AGENT")
Response.Write browser
โ
Or use BrowserCap.ini
for advanced browser detection (requires config).
๐ ASP โ Content Linking
link = "page.asp?id=" & articleID
Response.Write "<a href='" & link & "'>Read More</a>"
โ
Use QueryString
values to build navigation and filters.
๐ ASP โ Content Rotator
Simple content switcher:
contentList = Array("Welcome!", "Hello!", "Thanks for visiting.")
Randomize
i = Int((UBound(contentList) + 1) * Rnd)
Response.Write contentList(i)
โ Great for rotating tips, quotes, or headlines.
๐ Summary โ Recap & Next Steps
Classic ASP offers a rich toolkit of built-in functions and objects that streamline file handling, user input, error management, and dynamic output. These reusable helpers are key to building and maintaining robust legacy web apps.
๐ Key Takeaways:
- VBScript functions simplify strings, dates, and math operations
Request
,Response
, andServer
are the core I/O interfaces- FileSystemObject allows server-side file and folder manipulation
- Dictionary, Ad Rotator, and BrowserCap add flexibility to UIs
โ๏ธ Real-World Applications:
- File upload logging and email forms
- Banner ad rotation for monetization
- Form field validation with VBScript
- Session-aware UI logic and page includes
โ Frequently Asked Questions
โ What is the FileSystemObject in ASP?
โ
It allows you to read, write, delete, and inspect files and directories on the server.
โ How do I handle errors gracefully in Classic ASP?
โ
Use On Error Resume Next
, then check Err.Number
and Err.Description
.
โ Can I use dictionaries in Classic ASP like hashtables?
โ
Yes, using Scripting.Dictionary
.
โ Whatโs the purpose of Server.MapPath
?
โ
Converts virtual paths to physical server paths (e.g., "/data.txt"
โ "C:\inetpub\..."
).
Share Now :