ASP.NET Tutorial
Estimated reading: 4 minutes 293 views

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 #include files and global.asa
  • How Classic ASP handles procedures and session lifecycle

Topics Covered

Topic Description
Classic ASP โ€“ IntroductionOverview of Classic ASP and use cases
Classic ASP โ€“ SyntaxHow to write and separate code using <% %> tags
Classic ASP โ€“ VariablesDeclaring and using variables with Dim and Set
Classic ASP โ€“ ProceduresSubroutines and functions for reusable logic
Classic ASP โ€“ ConditionalsIf...Then, ElseIf, Select Case syntax
Classic ASP โ€“ LoopingFor, While, and Do Until loops
Classic ASP โ€“ FormsCapture and process form data using Request.Form()
Classic ASP โ€“ #includeInclude reusable code blocks in multiple pages
Classic ASP โ€“ global.asaDefine application/session-level events and variables
Classic ASP โ€“ Email HandlingSend emails using CDO.Message
Classic ASP โ€“ ExamplesReal-world code demonstrations and samples
Classic ASP โ€“ Certificate InfoRetrieve 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 path
  • virtual: 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, For follow VBScript rules
  • Request and Response manage form data and output
  • #include and global.asa provide 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 :
Share

๐Ÿ’ป Classic ASP โ€“ Logic & Scripting

Or Copy Link

CONTENTS
Scroll to Top