๐ป Classic ASP โ Logic & Scripting Guide โ Variables, Procedures, Conditionals, and Forms
๐งฒ Introduction โ What Is Classic ASP?
Classic ASP (Active Server Pages) is Microsoftโs early server-side scripting environment, built on VBScript or JScript, for creating dynamic, data-driven web pages. Although itโs largely replaced by ASP.NET, Classic ASP is still maintained in legacy systems.
๐ฏ In this guide, youโll learn:
- Classic ASP syntax and scripting model
- How to declare variables, write logic, and loop over data
- How to process forms and send emails
- How to use
#includefiles andglobal.asa - How Classic ASP handles procedures and session lifecycle
๐ Topics Covered
| ๐น Topic | ๐ Description |
|---|---|
| ๐ Classic ASP โ Introduction | Overview of Classic ASP and use cases |
| ๐งพ Classic ASP โ Syntax | How to write and separate code using <% %> tags |
| ๐งฎ Classic ASP โ Variables | Declaring and using variables with Dim and Set |
| ๐งฑ Classic ASP โ Procedures | Subroutines and functions for reusable logic |
| ๐ Classic ASP โ Conditionals | If...Then, ElseIf, Select Case syntax |
| ๐ Classic ASP โ Looping | For, While, and Do Until loops |
| ๐ Classic ASP โ Forms | Capture and process form data using Request.Form() |
๐ Classic ASP โ #include | Include reusable code blocks in multiple pages |
๐ Classic ASP โ global.asa | Define application/session-level events and variables |
| ๐ง Classic ASP โ Email Handling | Send emails using CDO.Message |
| ๐งช Classic ASP โ Examples | Real-world code demonstrations and samples |
| ๐ Classic ASP โ Certificate Info | Retrieve SSL and certificate details from requests |
๐งพ Classic ASP โ Syntax
Classic ASP code is written inside <% ... %> blocks.
<%
Response.Write "Hello, world!"
%>
โ
Use Response.Write or = shortcut:
<%= Now() %>
Supports VBScript (default) or JScript.
๐งฎ Classic ASP โ Variables
<%
Dim username
username = "admin"
Response.Write "Welcome " & username
%>
โ
Use Dim for declaration. Use Set for objects like:
Set conn = Server.CreateObject("ADODB.Connection")
๐งฑ Classic ASP โ Procedures
Sub ShowMessage(msg)
Response.Write "<p>" & msg & "</p>"
End Sub
Call ShowMessage("Hello ASP!")
โ
Use Function if return value is needed:
Function Add(a, b)
Add = a + b
End Function
๐ Classic ASP โ Conditionals
If score >= 90 Then
Response.Write "Grade: A"
ElseIf score >= 80 Then
Response.Write "Grade: B"
Else
Response.Write "Fail"
End If
โ
Select Case Alternative:
Select Case day
Case "Mon": Response.Write "Start"
Case "Fri": Response.Write "Weekend"
Case Else: Response.Write "Midweek"
End Select
๐ Classic ASP โ Looping
๐น For Loop
For i = 1 To 5
Response.Write i & "<br>"
Next
๐น While Loop
While i <= 5
Response.Write i & "<br>"
i = i + 1
Wend
โ
Use Do Until, Do While for flexible looping patterns.
๐ Classic ASP โ Forms
HTML Form:
<form method="post" action="submit.asp">
<input type="text" name="email" />
<input type="submit" value="Send" />
</form>
Form Processing:
<%
email = Request.Form("email")
Response.Write "You entered: " & email
%>
๐ Classic ASP โ #include
Reuse code across files:
<!--#include file="header.asp"-->
โ Types:
file: relative pathvirtual: site root-based path
๐ Classic ASP โ global.asa
Defines application/session events.
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
Sub Application_OnStart
Application("Visits") = 0
End Sub
Sub Session_OnStart
Session("UserRole") = "guest"
End Sub
</SCRIPT>
โ Common uses: counters, session defaults, logging.
๐ง Classic ASP โ Email Handling
Set msg = Server.CreateObject("CDO.Message")
msg.To = "admin@example.com"
msg.From = "noreply@example.com"
msg.Subject = "Contact Form"
msg.TextBody = "New submission!"
msg.Send
โ Works with SMTP servers like IIS or Office365.
๐งช Classic ASP โ Example
A Simple Calculator:
<%
a = CInt(Request("a"))
b = CInt(Request("b"))
sum = a + b
Response.Write "Sum is: " & sum
%>
๐ Classic ASP โ Certificate Info
cert = Request.ServerVariables("CERT_SUBJECT")
Response.Write "Cert: " & cert
โ Useful for secure login with client-side certificates.
๐ Summary โ Recap & Next Steps
Classic ASP provides a lightweight scripting model for building dynamic sites using VBScript or JScript. Even today, many legacy apps rely on these fundamental scripting and logic capabilities.
๐ Key Takeaways:
- Use
<% %>for scripting inside HTML Dim,Set,If,Forfollow VBScript rulesRequestandResponsemanage form data and output#includeandglobal.asaprovide modularity and session control
โ๏ธ Real-World Applications:
- Legacy CMS and admin panels
- Lightweight intranet dashboards
- Form processors and simple mailers
- Certificate-based secure pages
โ Frequently Asked Questions
โ What language does Classic ASP use?
โ
Mainly VBScript, but JScript (JavaScript) is also supported.
โ Can I run Classic ASP on modern servers?
โ
Yes, Classic ASP is supported on IIS 10+ with Windows features enabled.
โ What is the file extension for Classic ASP pages?
โ
.asp (e.g., login.asp)
โ Can I use databases in Classic ASP?
โ
Yes. Use ADODB.Connection and Recordset to connect to SQL Server, Access, etc.
Share Now :
