ASP Built-In Objects
K. Yue, copyright 2000
Created October 27, 2000

Introduction

The Request Object

Example:

servervar.asp: listing the contents of the server variables.

<body bgcolor="#ccccff">
<table border="1">
<tr>
<td><span style="background-color:#ffffcc;color:blue">Server Variable</span></td>
<td><span style="background-color:#ffffcc;color:blue">Value
</span></td>
</tr>
<% for each strKey in Request.ServerVariables %>
<tr>
<td><%= strKey %></td>
<td>
<% strVal = Request.ServerVariables(strKey)
   if (strVal = "") then
      strVal = "&nbsp;"
   end if
   Response.write(strVal)
%>
</td>
</tr>
<% next %>
</table>
</body>

Example:

QueryString

<body bgcolor="#ccccff">
<table border="1">
<tr>
<td><span style="background-color:#ffffcc;color:blue"
>Get Parameters</span></td>
<td><span style="background-color:#ffffcc;color:blue"
>Value</span></td>
</tr>
<% for each strKey in Request.QueryString %>
<tr>
<td><%= strKey %></td>
<td>
<% for i = 1 to Request.QueryString(strKey).Count
      Response.write ("[" & i & "]: " & _
      Request.QueryString(strKey)(i) & "<br>")
   next ' i
%>
</td>
</tr>
<% next %>
</table>
</body>

Notes:

Example:

QueryStringExampleSource.html:

<a href="QueryStringExample.asp?name=Bun+Yue&name=Joe+Lee&course=database">
Click here to see an example of QueryString
</a>

QueryStringExample.asp:

Course:
<%= Request.QueryString("course") %>. <br>
COURSE:
<%= Request.QueryString("COURSE") %>. <br>
Title:
<%= Request.QueryString("title") %>. <br>
Names are:
<%= Request.QueryString("name") %>. <br>
Name #1:
<%= Request.QueryString("name") (1)%>. <br>
Name #2:
<%= Request.QueryString("name") (2)%>. <br>

Example:

FormExampleSource.html:

<FORM ACTION ="FormExample.asp" METHOD=POST>
<H3>A simple example of forms</H3>
<P>
Your name:
<INPUT TYPE=TEXT SIZE=40 NAME=user>
<P>
Are you a CIS student?
<INPUT TYPE=CHECKBOX CHECKED name=cisstudent value=yes>
<P>
Your age:<BR>
<INPUT TYPE=RADIO NAME=age value="0-12">0-12<BR>
<INPUT TYPE=RADIO NAME=age value="13-19" CHECKED>13-19<BR>
<INPUT TYPE=RADIO NAME=age value="20-30">20-30<BR>
<INPUT TYPE=RADIO NAME=age value="31-45">31-45<BR>
<INPUT TYPE=RADIO NAME=age value="46-">46-<BR>

<P>
Your flavorite ice cream:<BR>
<SELECT NAME=icecream MULTIPLE><BR>
<OPTION value=Vanila SELECTED>Vanila<BR>
<OPTION value="Rocky Road">Rocky Road<BR>
<OPTION value=Strawberry>Strawberry<BR>
<OPTION value=Peach>Peach<BR>
<OPTION value="Chocolate Mint">Chocolate Mint<BR>
</SELECT>

<P>
Your comments:<BR>
<TEXTAREA NAME=comments ROWS=6 COLS=65>
</TEXTAREA>

<P>
<INPUT TYPE=SUBMIT VALUE="Submit">
<INPUT TYPE=RESET VALUE="Reset">
</FORM>

FormExample.asp:

<H3> Result of your form submission </H3>

<P>
Your name: <% = Request.Form("user") %>.<BR>
Your age: <% = Request.Form("age") %>.<BR>

<% IF Request.Form("cisstudent") = "yes" THEN %>
You are a CIS student.<BR>
<% ELSE %>
You are not a CIS student.<BR>
<% END IF %>

<P>
Your favorite ice cream:<BR>
<UL>
<% FOR EACH icecream in Request.Form("icecream") %>
<LI> <% = icecream %>
<% NEXT %>
</UL>
<P>
Your comments:
<P>
<% = Request.Form("comments") %>

The Response Object

 

 

Example:

redirect.asp: redirecting to another page.

<%
   Response.Redirect("http://sce.uhcl.edu/yue")
%>

Example:

cookies.asp

<%
Name = Request.QueryString("Name")
If (Name <> "") Then ' Set cookies.
   Response.Cookies("Name") = Name
   Response.Cookies("Name").Expires = #December 31, 2001#
Else ' Read from Cookie
   Name = Request.Cookies("Name")
End If

FavoriteColor = Request.QueryString("FavoriteColor")
If (FavoriteColor <> "") Then
   Response.Cookies("FavoriteColor") = FavoriteColor
   Response.Cookies("FavoriteColor").Expires = #December 31, 1998#
Else
   FavoriteColor = Request.Cookies("FavoriteColor")
End If
%>

<html>
<head>
<title>Simple Cookies</title>
</head>

<body bgcolor="#ccffff">
<%
If (Name = "" and FavoriteColor = "") Then
%>

<!-- Output form to get Name and or FavoriteColor -->
<form name="GetInput">
Your Name:
<input type="text" name="Name" value="<% =Name %>"><br>
Your Favorite Color:
<input type="text" name="FavoriteColor"
value="<% =FavoriteColor %>"><BR>
<input type="submit">
</form>

<% Else %>
<span style="color:<% = FavoriteColor %>">
<% =Name %></span>, welcome!
<% End If %>
</body>
</html>

Note:

Set-Cookie: ASPSESSIONIDQQQGQHWB=KLCNDCPCHPEGHBMNEINPDFNN; path=/
Set-Cookie: Name=Bun+Yue; expires=Mon, 31-Dec-2001 06:00:00 GMT; path=/yue


The Server Object

Example:

transfer.asp: transferring to another asp file in the same directory.

<%
   Server.Transfer("cookies.asp")
%>

Example:

mappath.asp: illustrating the mappath function.

<%
   Response.write("This URL file: " & _
      server.mappath(Request.ServerVariables("PATH_INFO")) & _
      "<br>")
   Response.write("cookies.asp: " & _
      server.mappath("cookies.asp") & _
   "<br>")
%>

The Application Object

Example:

ApplicationSet.asp:

<body bgcolor="#ccccff">
Setting author and id properties for
the Application object.
<%
Application("author") = "Kwok-Bun Yue"
Application("id") = "007"
%>
</body>

ApplicationContents.asp:

<body bgcolor="#ccccff">
<h2>Contents of the Application Objects:</h2>
<%
For Each Key in Application.Contents
   Response.Write Key + " = " + Application(Key) + "<br>"
Next
%>
</body>

ApplicationRemove.asp:

<body bgcolor="#ccccff">
Removing "author" and "id" from
the application object.
<%
Application.Contents.Remove("author")
Application.Contents.Remove("id")
%>

</body>

Example:

A Microsoft's example

<%
Application.Lock
Application("NumVisits") = Application("NumVisits") + 1
Application.Unlock
%>

This application page has been visited
<%= Application("NumVisits") %> times!

The Session Object

Global References

Example:

<OBJECT RUNAT=Server SCOPE=Application ID=MyConnection
        PROGID="ADODB.Connection">
REM Object Script
' With username yue and password sleeping.
MyConnection.open "Resume", "yue", "sleeping"
</OBJECT>