DevGuru ASP Quickref
DevGuru ASP Quickref
Trademark Information.
Welcome to the DevGuru Built-in ASP Objects Quick Reference guide. This is a valuable 71
page reference source that explains and provides comprehensive, working examples of code
for all of the collections, events, methods, and properties belonging to the seven Built-in Active
Server Pages objects.
● ASPError
● ObjectContext
● Request
● Response
● Server
● Session
In the good old days (a few years ago!), most Web sites were created with HTML and simply
displayed static pages. A few of the more adventurous programmers would use C or Perl to
design a dynamic Web site utilizing the CGI technology. However, these techniques were
plagued with security concerns and did not scale well to large sites. So, in general, dynamic
sites remained relatively few in number and were time consuming and expensive to create.
The introduction of the scripting languages, which could be embedded inside HTML code,
opened new doors for dynamic site development. Active Server Pages (ASP), which managed
to arrive just in time for the explosive growth of the World Wide Web, was a next logical step
for Web-based application development. Introduced in 1996 by Microsoft, Active Server Pages
proved to be an exciting, new technology that extended standard HTML by adding built-in
objects, server-side scripts, access to databases, and ActiveX components. Another important
development by Microsoft was to make the ASP scripting environment compliant with the
Component Object Model (COM). COM created a standard communication mechanism
between components. This step allowed non-vendor components, such as those offered by
DevGuru, to share their properties, methods and events with other components in a process
called OLE automation. Non-vendor components greatly extend the functionality of ASP
applications.
The true power of ASP is the ease and rapidity with which developers can create and
implement dynamic Web sites. Indeed, for today's modern Web commerce, a dynamic,
database-driven, server-side application that interacts with the client is the norm.
ASP employs a scripting environment and VBScript is the default scripting language of choice.
However, you can use other languages (such as JScript and Perl) as long as they have a
scripting engine that is compatible with the ActiveX scripting standard.
Fortunately, you are not limited to just using Active Server Pages with Microsoft's Internet
Information Server (IIS) and this has enhanced the popularity of ASP. For example, Chili!Soft is
a proven industry leader in providing ASP engines for use with Web servers from FastTrack,
Lotus, Netscape, O'Reilly, and many others. And Halcyon Software offers a brilliant Java-
based implementation of the Microsoft ASP framework, allowing developers to deploy ASP
applications on any platform.
Meanwhile, ASP continues to evolve. With the arrival of the millennium came the arrival of ASP
version 3.0. Version 3.0 was released along with Internet Information Server (IIS) version 5.0
as part of the highly anticipated Microsoft Windows 2000. By far, the most important new
feature of version 3.0 is the addition of a seventh, intrinsic object called ASPError which should
greatly simplify error handling. Other new features include the addition of three new methods to
the Server object, and two new methods to both the Application object and the Session object.
Active Server Pages has ultimately proven to be of significant value to developers and fueled a
revolution in the development of Web-based applications.
The future of ASP will continue to be very interesting. Later this year (summer?), ASP-plus,
which is now referred to as [Link], will be formally released by Microsoft. It allows the use
of the Visual Basic, C#, and Visual C++ languages with ASP.
Contents
Application
Session
ClientCertificate
Cookies
Request
Response
Form
QueryString
ServerVariables
StaticObjects
Application
Session
OnEnd
Application
Session
OnStart
Application
Session
OnTransactionAbort
OnTransactionCommit
Abandon CreateObject
AddHeader End
AppendToLog Execute
BinaryRead Flush
BinaryWrite GetLastError
Clear HTMLEncode
[Link] MapPath
Application Redirect
Session SetAbort
[Link] SetComplete
Application Transfer
Session URLEncode
Write
Application
ASPError
ObjectContext
Request
Response
Server
Session
ASPCode File
ASPDescription IsClientConnected
Buffer LCID
CacheControl Line
Category Number
Charset Pics
CodePage ScriptTimeout
Column SessionID
ContentType Source
Description Status
Expires Timeout
ExpiresAbsolute
Abandon [Link] OnTransactionAbort
AddHeader Application OnTransactionCommit
AppendToLog Session Pics
Application CreateObject QueryString
ASPCode Description Redirect
ASPDescription End Request
ASPError Execute Response
BinaryRead Expires ScriptTimeout
BinaryWrite ExpiresAbsolute Server
Buffer File ServerVariables
CacheControl Flush Session
Category Form SessionID
Charset GetLastError SetAbort
Clear HTMLEncode SetComplete
ClientCertificate IsClientConnected Source
CodePage LCID StaticObjects
Column Line Application
Contents MapPath Session
Application Number Status
Session ObjectContext Timeout
ContentType OnEnd Transfer
Cookies Application URLEncode
Request Session Write
Response OnStart
[Link] Application
Application Session
Session
METHOD: [Link]
[Link]
The Abandon method terminates a user session, destroys all the objects in the current
Session object, and releases its resources. However, this deletion will not occur until all of the
script is processed for the current page. When the session ends, the OnEnd event handler is
called. By default, even if you do not call Abandon, the Session object is terminated after
twenty minutes of idle time.
Code:
----------------[Link]-------------------
<%
[Link] "Your SessionID is " & [Link]
Session("Application") = "DevSite"
[Link]
[Link] "The Application name is " & Session("Application")
%>
----------------[Link]---------------------
<%
[Link] "Your SessionID is " & [Link]
%>
Output:
------------[Link]-------------------------
Your SessionID is 465107831
The Application name is DevSite
-----------[Link]--------------------------
Your SessionID is 465107831
METHOD: [Link]
Response. AddHeader Name, Value
The AddHeader method adds a new named HTTP header with a specific value to the HTTP
response. Note that once a header has been added, it cannot be removed. This method must
be called before any output is sent to the client unless the [Link] is set to true.
Name
The Name argument is the name of the new header variable. The name cannot contain any
underscores ( _ ).
Value
The Value argument is the initial value of the new header variable.
Code:
<%
[Link] "MyHeader", "ERROR"
%>
METHOD: [Link]
[Link](String)
The AppendToLog method adds (appends) a string to the end of the entry of the Web server
log for this request.
String
The String argument is the string to be appended. The string can have a maximum length of
80 characters. It cannot contain commas because the log is comma-delineated.
Code:
<%
[Link]("Error in Processing")
%>
The Application object shares, stores, and retrieves information in response to requests from
users to the application.
COLLECTION PROPERTIES
Contents Object
A collection of all of the items which have been created and added to the Application object
during client sessions through script commands, such as the [Link], rather than
by using the HTML <OBJECT> tag.
StaticObjects Object
A collection of all of the items which have been created and added to the Application object
during client sessions by using the HTML <OBJECT> tag, rather than using script commands.
METHODS
Lock Method
The Lock method prevents all other users from making changes in the Application object.
Unlock Method
The Unlock method allows any user to have access to any of the Application object
properties in order to make changes.
EVENTS
OnEnd Event
The OnEnd event occurs when the Application quits. This should not occur unless all user
sessions are over. The signal of this event will run a handler script in the [Link] file, if the
script exist.
OnStart Event
The OnStart event occurs before the start of any new session by a user (i.e., before the
Application object is first referenced). The signal of this event will run a handler script in the
[Link] file, if the script exist.
COLLECTION PROPERTY: [Link]
[Link](Key)
The Contents collection property contains a list of the items that have been created and added
to the Application object. Objects can be added to the collection by using [Link]
or by assigning scalar variables.
You can iterate through a collection using a For Each item in ... Next loop.
Key
Code:
<%
Application("name") = "Application Maker"
Application("publishdate") = "05/15/01"
Application("author") = "DevGuru"
Set Application("Obj1") = [Link]("[Link]")
Output:
name=Application Maker
publishdate=05/15/01
author=DevGuru
OBJ1 is an object.
COLLECTION PROPERTY: [Link]
[Link](Key)
The StaticObjects collection property is a collection that contains of all of the items created
within the Application using the HTML <OBJECT> tag. You can use this collection to find the
value of any property for any object.
You can iterate through a collection using a For Each item in ... Next loop.
Key
Code:
----------[Link]-------------
<OBJECT RUNAT=Server SCOPE=Application ID=MyInfo PROGID="[Link]">
</OBJECT>
-----------[Link]-----------------
<%
For Each Item In [Link]
[Link] Item & "<BR>"
Next
%>
Output:
MyInfo
MyConnection
MyADRot
METHOD: [Link]
Implemented in version 3.0
[Link] (Name|Integer)
You may use only one of the two possible choices for the mandatory argument.
Name or Integer
The Name argument is the name of the item to be deleted. It must be enclosed in a pair of
quotes.
The Integer argument is the position number of the item in the collection to be deleted. The
numbering sequence for a collection starts at one, not zero.
Code:
<%
Application("name") = "Application Maker"
Application("publishdate") = "05/15/01"
Application("author") = "DevGuru"
Set Application("Obj1") = [Link]("[Link]")
[Link](1)
[Link]("publishdate")
Output:
author=DevGuru
Obj1 is an object.
METHOD: [Link]
Implemented in version 3.0
[Link]
The [Link] method deletes all items that are in the [Link]
collection.
Code:
<%
[Link]( )
%>
METHOD: [Link]
[Link]
The Lock method prevents all other users from changing any of the variables in the Contents
collection of the Application object.
You can use the Unlock method to explicitly remove the Lock placed upon the Application
object. Remember, to completely unlock an object, you must call Unlock the same number of
times you have called Lock. Fortunately, the server will automatically unlock all locks placed
on the object when the script times out or the .asp file ends.
Code:
<%
[Link]
%>
METHOD: [Link]
[Link]
The Unlock method is used to explicitly unlock the variables in the Contents collection of the
Application object.
In contrast, the Lock method prevents all other users from changing any of the variables in the
Contents collection of the Application object. This ability to lock is required since Application
objects are designed to be shared among an unlimited number of users. Therefore, you need
the ability to allow only one user at a time to make changes and you do this by locking
everybody else out.
Remember, to completely unlock an object, you must call Unlock the same number of times
you have called Lock. Fortunately, the server will automatically unlock all locks placed on the
object when the script times out or the .asp file ends.
Code:
<%
[Link]
%>
EVENT: Application_OnEnd
The Application_OnEnd event occurs when the Application ends. This should only happen
when the web server is stopped by the operating system in a normal manner. The
Application_OnEnd event is simply a subroutine with a reserved name that is placed within
the [Link] file. It can contain any script that you wish to run after all user sessions are
finished. For example, you may wish to compute and store statistics on user sessions for future
reference.
Note: The only built-in ASP objects available from within the OnEnd event handler are Server
and Application.
Code:
-------------------[Link]--------------------------
<script Language="VBScript" RUNAT=Server>
Sub Application_OnEnd()
Calculate_Stats()
End Sub
Sub Application_OnStart()
Application("NumSession") = 0
Application("NumVisited") = 0
End Sub
Sub Session_OnEnd()
Application("NumSession") = Application("NumSession") - 1
End Sub
Sub Session_OnStart()
Application("NumSession") = Application("NumSession") + 1
Application("NumVisited") = Application("NumVisited") + 1
End Sub
</script>
-------------------[Link]----------------------------
[Link] "You are " & Application("NumSession") & " of " & Application("NumVisited") &
" users."
EVENT: Application_OnStart
The Application_OnStart event occurs before the beginning of any user session. The only
built-in ASP objects available from within the OnStart event handler are Server and Application.
The Application_OnStart event is simply a subroutine with a reserved name that is placed
within the [Link] file. It contains any script that you wish to run before the first user
session. For example, you could use the [Link] property to automatically end an
idle user session after 10 minutes.
Note that you must declare the scripting language used to code the event script on the first line
of the [Link] file.
Code:
-------------------[Link]--------------------------
<script Language="VBScript" RUNAT=Server>
Sub Application_OnEnd()
End Sub
Sub Application_OnStart()
Application("NumSession") = 0
Application("NumVisited") = 0
[Link] = 10
End Sub
Sub Session_OnEnd()
Application("NumSession") = Application("NumSession") - 1
End Sub
Sub Session_OnStart()
Application("NumSession") = Application("NumSession") + 1
Application("NumVisited") = Application("NumVisited") + 1
End Sub
</script>
-------------------[Link]----------------------------
[Link] "You are " & Application("NumSession") & " of " & Application("NumVisited") &
" users."
Output:
You are 1 of 1 users.
OBJECT: ASPError
Implemented in version 3.0
The ASPError object is used to obtain detailed information on an error condition. This
information, provided by the nine read-only properties of ASPError, can only be accessed by
using the [Link] method.
PROPERTIES
ASPCode Property
The ASPCode property returns the error code generated by IIS.
ASPDescription Property
The ASPDescription property returns a string that provides more detailed description of the
error as compared to the short description returned by the Description property. (Not available
for all errors.)
Category Property
The Category property returns a string indicating if the error was generated by IIS, an object,
or a scripting language.
Column Property
The Column property returns a long integer defining the column position inside the ASP file
where the error occurred.
Description Property
The Description property returns a string that is a short description of the error. If you desire a
longer description, use the ASPDescription property.
File Property
The File property returns the name of the ASP (Active Server Page) file in which the error
occurred.
Line Property
The Line property returns an long integer defining the line number inside the ASP file where
the error occurred.
Number Property
The Number property returns a long integer defining the standard COM error code returned by
a COM component.
Source Property
The Source property returns a string with the actual line from the source code where the error
occurred (if available).
METHOD: [Link]
Implemented in version 3.0
[Link]( )
The GetLastError method returns an instance of the ASPError object. The ASPError object
exposes (gives access to) nine read-only properties that provide detailed information about an
error that has occurred.
Once an ASP file has sent content to a client, you cannot use the GetLastError method to
access information about the error.
The types of errors handled by the ASPError method are called "500;100 custom errors" and
there are three major types: pre-processing, runtime, and script compiling.
By default, the error information is sent to the "\iishelp\common\[Link]" file. This is a new
file that is part of IIS version 5.0 and does not exist in earlier versions. Here is the source code
for the [Link] file. Since you can access this file, you can customize this code to suit
your programming needs.
Also, you can create your own personal, custom ASP error file by having the Internet
Information Server (IIS) 5.0 redirect the 500;100 custom errors to an error file that you create.
In your ASP error file, you can run any ASP code you desire.
Here is the general concept of how to access the nine ASPError properties in an error file
Code:
<%
Dim objErrorInfo
Set objErrorInfo = [Link]
It is presented to demonstrate how Microsoft programmers use the ASPError object to display errors. Certain
parts of the code have been colorized to call your attention to specific procedures.
If [Link] Then
[Link]
[Link] = "500 Internal Server Error"
[Link] = "text/html"
[Link] = 0
End If
<html dir=ltr>
<head>
<style>
a:link {font:8pt/11pt verdana; color:FF0000}
a:visited {font:8pt/11pt verdana; color:#4e4e4e}
</style>
<script>
function Homepage(){
<!--
// in real bits, urls get returned to our script like this:
// res://[Link]/http_404.htm#[Link]
//for the href, we need a valid URL to the domain. We search for the # symbol to find the begining
//of the true URL, and add 1 to skip it - this is the BeginURL value. We use serverIndex as the end marker.
//urlresult=[Link](protocolIndex - 4,serverIndex);
BeginURL=[Link]("#",1) + 1;
urlresult=[Link](BeginURL,serverIndex);
//for display, we need to skip after [Link] and go to the next slash
displayresult=[Link](protocolIndex + 3 ,serverIndex);
[Link]('<A HREF="' + urlresult + '">' + displayresult + "</a>");
}
//-->
</script>
<body bgcolor="FFFFFF">
<tr>
<td align="left" valign="middle" width="360">
<h1 style="COLOR:000000; FONT: 13pt/15pt verdana"><!--Problem-->The page cannot be displayed</h1>
</td>
</tr>
<tr>
<td width="400" colspan="2">
<font style="COLOR:000000; FONT: 8pt/11pt verdana">There is a problem with the page you are trying to
reach and it cannot be displayed.</font></td>
</tr>
<tr>
<td width="400" colspan="2">
<font style="COLOR:000000; FONT: 8pt/11pt verdana">
<ul>
<li id="instructionsText1">Click the
<a href="javascript:[Link]()">
Refresh</a> button, or try again later.<br>
</li>
<li>Open the
<script>
<!--
if (!(([Link]("MSIE") > 0) && ([Link](0) == "2")))
{
Homepage();
}
//-->
</script>
home page, and then look for links to the information you want. </li>
</ul>
<h2 style="font:8pt/11pt verdana; color:000000">HTTP 500.100 - Internal Server Error - ASP error<br>
Internet Information Services</h2>
<ul>
<li>Error Type:<br>
<%
[Link] [Link]
If [Link] > "" Then [Link] ", " & [Link]
[Link] " (0x" & Hex([Link]) & ")" & "<br>"
blnErrorWritten = False
' Only show the Source if it is available and the request is from the same machine as IIS
If [Link] > "" Then
strServername = LCase([Link]("SERVER_NAME"))
strServerIP = [Link]("LOCAL_ADDR")
strRemoteIP = [Link]("REMOTE_ADDR")
If (strServername = "localhost" Or strServerIP = strRemoteIP) And [Link]
<> "?" Then
[Link] [Link]
If [Link] > 0 Then [Link] ", line " & [Link]
If [Link] > 0 Then [Link] ", column " & [Link]
[Link] "<br>"
[Link] "<font style=""COLOR:000000; FONT: 8pt/11pt courier
new""><b>"
[Link] [Link]([Link]) & "<br>"
If [Link] > 0 Then [Link] String(([Link] - 1), "-")
& "^<br>"
[Link] "</b></font>"
blnErrorWritten = True
End If
End If
If Not blnErrorWritten And [Link] <> "?" Then
[Link] "<b>" & [Link]
If [Link] > 0 Then [Link] ", line " & [Link]
If [Link]> 0 Then [Link] ", column " & [Link]
[Link] "</b><br>"
End If
%>
</li>
<p>
<li>Browser Type:<br>
<%= [Link]("HTTP_USER_AGENT") %>
</li>
<p>
<li>Page:<br>
<%
strMethod = [Link]("REQUEST_METHOD")
[Link] [Link]("SCRIPT_NAME")
[Link] "</li>"
%>
<p>
<li>Time:<br>
<%
datNow = Now()
[Link]([Link]) & _
"&os=&over=&hrd=&Opt1=" & [Link]([Link]) & "&Opt2=" &
[Link]([Link]) & _
"&Opt3=" & [Link]([Link])
strURL = "[Link] & _
strQueryString
%>
<a href="<%= strURL %>">Microsoft Support</a>
</li>
</p>
</font></td>
</tr>
</table>
</body>
</html>
METHOD: [Link]
[Link](Count)
The BinaryRead method retrieves the unparsed data that was sent to the server from the user
as part of an HTTP POST (i.e. an HTML FORM request). The data read is stored in a
SafeArray which is a variant, structure-like array that, in addition to storing the data, also stores
the number of dimensions of the array and the upper bounds of those dimensions.
You can write binary data into the response stream (info sent to a client) by using the
[Link](BinaryData) method. The BinaryData argument is simply the output
(the SafeArray) from [Link]. For example, you could retrieve an image from a
database with [Link] and send it to a client using [Link].
Using [Link] after calling BinaryRead, and vice-versa, will cause an error.
Count
Before the method is executed, Count contains the number of bytes to be read. After the
method has returned, Count contains the actual number of bytes read. The number read
should be less than or equal to the total byte count value returned by [Link].
Code:
<%
Dim ByteCount, BinRead
ByteCount = [Link]
BinRead = [Link](ByteCount)
...
[Link](BinRead)
%>
METHOD: [Link]
[Link](Data)
The BinaryWrite method writes nonstring data (binary data) to the current HTTP output
without any character set conversion.
This method can use the output of the [Link] method. For example, you could
retrieve an image from a database with [Link] and send it to a client using
[Link].
Data
Code:
-------------------[Link]------------------
<HTML>
<HEAD>
</HEAD>
<BODY>
<form action="[Link]" method="POST">
Name:<input type="Text" name="name" maxlength="30"><BR>
Age:<input type="Text" name="age" maxlength="10"><BR>
Sex:<input type="Text" name="Sex" maxlength="10"><BR>
<input type="Submit" name="submit" value="submit"><BR>
</form>
</BODY>
</HTML>
-------------------[Link]------------------
<%
bytecount = [Link]
binread = [Link](bytecount)
[Link] binread
%>
Output:
name=Jane&age=25&Sex=Female&submit=submit
PROPERTY: [Link]
Modified in version 3.0
The Buffer property tells whether to buffer (temporarily store) the output page being sent to the
browser. A response is not sent to the browser until all scripts are processed, or the Flush or
End methods are called. The Buffer property cannot be set or changed after the server has
sent output to the browser. Therefore, you need to set the Buffer property on the first line of
the ASP page. If the Buffer is set to True, then the server will buffer the output. If it is set to
False, then no buffering occurs.
In ASP version 2.0 the default value is False and no buffering is done.
In ASP version 3.0 the default value is True and the server will buffer the output. However,
there is a quirk concerning the default value of [Link] that is dependent upon how
Windows 2000 (which contains IIS 5.0 and ASP 3.0) is initially installed on your computer. If
you do a clean install, the default value will be True. If the install is an upgrade, the default
value will be False.
In the code example, there is no output because the loop does not finish and the Buffer will not
empty until the script has finished. If the buffer was set to False, then the [Link]
would write the number to the browser every time it went through the loop.
Code:
<%
[Link] = TRUE
x=0
Do
x = x+1
[Link] x & "<BR>"
Loop
%>
PROPERTY: [Link]
The CacheControl property allows a proxy server to cache an Actice Server Page. A proxy
server is used to speed up the retrieval of a web page by keeping a local copy of the web page
in a cache.
The CacheControl property can only be set equal to "Public" or "Private". The pair of double
quotes are required.
If the CacheControl property is set equal to "Public", then caching can occur.
If the CacheControl property is set equal to "Private", then caching cannot occur. By default,
a proxy server will not keep a cache copy.
You can use [Link] and [Link] to set a time and/or date
limit on the existence of the cache.
Code:
<% [Link]("MS_Kanji") %>
METHOD: [Link]
[Link]
The Clear method clears (erases) any buffered HTML output. It does not erase the response
headers, only the body. If the buffer does not exist, because [Link] was set to
False, a runtime error will occur.
Note that in ASP version 2.0, the default for [Link] is set to False, however in ASP
version 3.0, the default for [Link] is set to True.
Code:
<%
[Link]
%>
COLLECTION PROPERTY: [Link]
[Link](Key [SubField])
One procedure for maintaining security in electronic transactions is to use the Secure Socket
Layers (SSL) protocol. If in use by the browser, this protocol sends certificates to the server
that identifies the browser. The ClientCertificate collection property retrieves the values of
these client certification fields. An interesting feature of this protocol is the use of the https://
prefix rather than the normal [Link]
You can iterate through a collection using a For Each item in ... Next loop.
Key
The Key argument is a string that specifies the name of the field to retrieve. Note the use of the
double quotes in the code example. A certificate contains the following seven fields:
Flags. There are two flags that provide additional client certificate information.
The ceCertPresent flag indicates a client certificate is present. The
ceUnrecognizedIssuer flag indicates the last certification in this chain is from
an unknown user.
Issuer is a string containing the subfield values that provide information about
the issuer of the certificate.
Subject is a string containing the subfield values that provide information about
the subject of the certificate.
Subfield
The optional Subfield argument is used only with the Issuer or the Subject key fields. It is
added to the key field as a suffix. For example, IssuerL which is the locality of the Issuer. Or,
SubjectCN which gives the common name of the user.
Code:
<HTML>
<HEAD>
</HEAD>
<BODY>
This certification is valid from <%= [Link]("ValidFrom") %> until <%=
[Link]("ValidUntil") %>.
</BODY>
</HTML>
Output:
This certification is valid from 9/26/96 [Link] PM until 9/26/97 [Link] PM.
PROPERTY: [Link]
The CodePage property specifies which server codepage to use when displaying dynamic
Active Server Pages. A codepage is a character set used for symbol mapping. The default
value of the CodePage varies by location and language. If you specify a new CodePage
property, it will exist only for the duration of the session.
Code:
The Contents collection property contains a list of all of the items that has been created and
added to the Session object through script commands, rather than by using the HTML
<OBJECT> tag.
You can iterate through a collection using a For Each item in ... Next loop.
Key
Code:
<%
Session("name") = "Application Maker"
Session("publishdate") = "05/01/99"
Session("author") = "ISSI"
Set Session("Obj1") = [Link]("[Link]")
Output:
NAME=Application Maker
PUBLISHDATE=05/01/99
AUTHOR=ISSI
OBJ1 is an object.
PROPERTY: [Link]
The ContentType property specifies the HTTP content type, which includes a type/subtype, for
the response header. The type is the general content, and the subtype is the specific content.
The default is text/HTML.
This example code will produce a 2 X 2 Excel Spreadsheet in a browser, if Excel is installed on
the client machine.
Code:
<% [Link] = "application/[Link]-excel" %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<TABLE>
<TR>
<TD>2</TD><!--- Cell : A1 --->
<TD>4</TD><!--- Cell : B1 --->
</TR>
<TR>
<TD>5</TD><!--- Cell : A2 --->
<TD>6</TD><!--- Cell : B2 --->
</TR>
</TABLE>
</BODY>
</HTML>
COLLECTION PROPERTY: [Link]
[Link](Name)[(Key)|.Attribute]
The Cookies collection property allows you to access the values of the browser cookies sent in
by requests.
Name
Key
The Key argument specifies which value from the cookie dictionary to retrieve.
Attribute
You can iterate through a collection using a For Each ... Next loop.
Code:
<%
For Each objCK In [Link]
[Link] objCK & " = " & [Link](objCK) & "<br>"
Next
%>
Output:
PRD2 = VBScript
PRD1 = ASP
MAIN = DevSite
COLLECTION PROPERTY [Link]
[Link](Name)[(Key)|.Attribute]=Value
The Cookies collection property assignes a new value to a cookie, if it exists; otherwise, the
cookie is created and the value is assigned.
Name
Value
The Value argument specifies the value to assign to the key or attribute.
Attribute
The optional Attribute argument can one of the five following parameters:
Domain is write-only and allows pages on a domain made up of more than one
server to share cookie information.
Expires is write-only and is the date on which the cookie expires. Unless a date
is specified, the cookie will expire when the session ends. If a date is specified,
the cookie will be stored on the client's disk after the session ends.
HasKeys is read-only and uses Boolean values to specify whether the cookie
contains keys.
Path is write-only and if set, the cookie is sent by this path. If this argument is
not set, the default is the application path.
Key
The optional Key argument specifies the Key to which the Value is assigned.
Code:
<%
[Link]("myProduct")("Main") = "DevSite"
[Link]("myProduct")("Prd1") = "ASP"
[Link]("myProduct")("Prd2") = "VBScript"
[Link] [Link]("myProduct")
%>
Output:
PRD2=VBScript&PRD1=ASP&MAIN=DevSite
METHOD: [Link]
Implemented in version 3.0
[Link] (Name|Integer)
The [Link] method is used to delete one specified item in the [Link]
collection.
You may use only one of the two possible choices for the mandatory argument.
Name or Integer
The Name argument is the name of the item to be deleted. It must be enclosed in a pair of
quotes.
The Integer argument is the position number of the item in the collection to be deleted. The
numbering sequence for a collection starts at one, not zero.
Code:
<%
Session("name") = "Session Maker"
Session("publishdate") = "05/15/01"
Session("author") = "DevGuru"
Set Session("Obj1") = [Link]("[Link]")
[Link](1)
[Link]("publishdate")
Output:
author=DevGuru
Obj1 is an object.
METHOD: [Link]
Implemented in version 3.0
[Link]
The [Link] method deletes all items that are in the [Link]
collection.
Code:
<%
[Link]( )
%>
METHOD: [Link]
[Link](ObjectID)
The CreateObject method is probably the most widely used and the most important method
available through the Built-in Actice Server Pages Objects. It allows you to instantiate the
components of a script, or in different terms, create an instance of other objects. As a direct
consequence, you can use and access any collections, events, methods, and properties
associated with these objects.
ObjectID
Code:
<% Set myconn = [Link]("[Link]") %>
METHOD: [Link]
[Link]
The End method orders the web server to stop processing the script. The current results are
returned and no further processing occurs. If [Link] is set to True, [Link]
will flush the buffer and then end.
Note that in ASP version 2.0, the default for [Link] is set to False, however in ASP
version 3.0, the default for [Link] is set to True.
In the example, the second [Link] will not be displayed in the output.
Code:
<%
[Link] "Hello World"
[Link]
[Link] "Is this the End?"
%>
Output:
Hello World
METHOD: [Link]
Implemented in version 3.0
[Link](Path)
The Execute method allows you to call another ASP page from inside an ASP page. When the
called ASP page completes its tasks, you are then returned to the calling ASP page. The
overall effect is very similar to a function or subroutine call. Any text or output from the called
ASP page will be displayed on the calling ASP page. The Execute method is a more useful
alternative to using server-side includes.
In contrast, the Transfer method allows you to transfer from one ASP page to another without
returning to the calling ASP page.
Path
The Path argument is a string specifying either the absolute or relative path of the ASP page
being called. The file name must be included in the path. The entire Path must be enclosed
inside a pair of quotes. The Path argument cannot include a query string, however, any query
string that was available to the calling ASP page will be available to the called ASP page.
Code:
----------[Link]----------
<HTML>
<BODY>
</BODY>
</HTML>
----------[Link]----------
<%
[Link] "pink"
%>
Output:
How now pink cow?
PROPERTY: [Link]
The Expires property specifies a length of time in minutes before a response page cached on
the browser expires.
The first line of code causes the page to be refreshed (reloaded) every time it is accessed,
rather than being stored in a cache.
In the second example, if the user returns to this page before the 15 minutes are up, the
cached version of the page will be displayed.
The following code specifies that the page will expire at 6:00 PM on May 15th of 1999. You
must use a 24 hour clock for the time and four digits for the year.
The Flush method immediately sends all current buffered page content to the client if the
[Link] property is set to True.
If the buffer does not exist, because [Link] is set to False, a runtime error will
occur.
Note that in ASP version 2.0, the default for [Link] is set to False, however in ASP
version 3.0, the default for [Link] is set to True.
Code:
<%
[Link]
%>
COLLECTION PROPERTY: [Link]
[Link](Element)[(Index)|.Count]
The FORM collection property contains, and allows you to retrieve, the values of the <FORM>
elements posted to a request form using the POST method.
You can iterate through a collection using a For Each item in ... Next loop.
Element
The Element argument is the name of the <FORM> element which is used to retrieve a value.
Index
The Index argument is used when the Element argument has more than one value. It is an
integer, ranging from 1 to [Link](Element).Count, which is used to select values from
a <FORM> element. Count is the total number of multiple values.
Code:
-------------------[Link]------------------------
<HTML>
<HEAD>
</HEAD>
<BODY>
<form action="[Link]" method="POST">
Name:<input type="Text" name="Name" maxlength="20"><br>
Company:<input type="Text" name="Company" maxlength="20"><br>
Position:<input type="Text" name="Position" maxlength="20"><br>
Address:<textarea name="Address" rows="3"></textarea><br>
Phone:<input type="Text" name="Phone" maxlength="20"><br>
<input type="Submit" name="Submit" value="Submit">
</form>
</BODY>
</HTML>
-------------------[Link]------------------------
<HTML>
<HEAD>
</HEAD>
<BODY>
<% [Link] [Link]("Name")%> works for
<% [Link] [Link]("Company") %> at address
<% [Link] [Link]("Address") %> as a
<% [Link] [Link]("Position") %>.<br>
</BODY>
</HTML>
Output:
Jane Doe works for ISSI at address 5609 Kington Pike Knoville, TN as a Web Designer.
METHOD: [Link]
Server. HTMLEncode (String)
The HTMLEncode method applies HTML encoding syntax to a specified string of ASCII
characters. For example, this allows you to display a HTML tag on a web page and not have it
treated as an actual tag.
String
Code:
<% [Link] [Link]("The tag for a table is: <Table>") %>
Output:
The tag for a table is: <Table>
Browser Output:
The tag for a table is: <Table>
PROPERTY: [Link]
Modified in version 3.0
The IsClientConnected property determines if the client has disconnected from the server
since the last [Link]. This property is particularly useful since it will prevent the
server from continuing to attempt to pass information after an unexpected disconnect.
In ASP 2.0, you must first attempt to pass information to the client in order to use this property.
However, in ASP 3.0 you can check the response of using this property before passing any
content to the client. (Thus, a simple test will prevent the server from performing unneccesary
work.)
In the example code, the output will be a list of all the book titles that are in the database.
However, if the user stops the connection to the server, then the only a partial list of titles will
be created.
Code:
<%
set connDB=[Link]("[Link]")
[Link] "books", "", ""
mySQL="select * from books"
Set rsBookSrch = [Link]("[Link]")
[Link] mySQL, connDB, adOpenStatic, adLockPessimistic
%>
<HTML>
<HEAD>
</HEAD>
<BODY>
<%
Do until ([Link] or [Link]=false)
[Link] [Link]("Title") %> <br>
<% [Link]
Loop
[Link]
[Link]
%>
</BODY>
</HTML>
PROPERTY: [Link]
The LCID property uses the location identifier number to access information on display format
issues, such as currency, date, and time, that are specific to a location or region. The location
identifier number uniquely defines a geographic location or region. For example, the location
identifier number for France is 1036.
Code:
<%
[Link] "This is the LCID for this page " & [Link] & "<BR>"
[Link] "This is the Time and Date format for the above LCID: " & NOW() & "<BR>"
[Link] = 1033
[Link] "This is the LCID for this page now " & [Link] & "<BR>"
[Link] "This is the Time and Date format for the above LCID: " & NOW() & "<BR>"
[Link] = 3079
%>
Output:
This is the LCID for this page 1033
This is the Time and Date format for the above LCID 5/12/99 [Link] PM
This is the LCID for this page now 3079
This is the Time and Date format for the above LCID 12.05.99 [Link]
METHOD: [Link]
[Link](Path)
The MapPath method maps a relative or virtual path to a physical path. This method does not
check for the validity or the existence of the physical path. If the path starts with a forward or
backward slash, the method returns the path as if the path is a full virtual path. If the path does
not start with a slash, then the method returns the path relative to the directory of the ASP file
being processed.
Path
Code:
<HTML>
<HEAD>
</HEAD>
<BODY>
The path of this file is <% [Link] [Link]("[Link]")
%>
The path of the file1 is <% [Link] [Link]("\[Link]")
%>
The path of the file2 is <% [Link] [Link]("test\[Link]")
%>
The path of the file3 is <% [Link] [Link]("\")
%>
</BODY>
</HTML>
Output:
The path of this file is D:\Inetpub\wwwroot\[Link]
The path of the file1 is D:\Inetpub\wwwroot\[Link]
The path of the file2 is D:\Inetpub\wwwroot\test\[Link]
The path of the file3 is D:\Inetpub\wwwroot
OBJECT: ObjectContext
The ObjectContext object is used to control Active Server Pages transactions which are
managed by the Microsoft Transaction Server (MTS). You may either complete (commit) or
abort a transaction.
The @Transaction directive must be on the first line of the .asp file in order to use this object
(see code examples). The @Transaction directive causes a transaction to run to completetion
unless an abort occurs.
METHODS
SetAbort Method
The SetAbort method declares that a transaction has not been completed and resources
should not be updated.
SetComplete Method
The SetComplete method declares that the transaction has been completed and resources
can be updated.
EVENTS
OnTransactionAbort Event
The OnTransactionAbort event occurs when a transaction has been aborted for some kind of
processing error. The signal of this event will run a handler script in the same file, if it exist.
OnTransactionCommit Event
The OnTransactionCommit event occurs when a transaction has been successfully
completed. The signal of this event will run a handler script in the same file, if it exist.
METHOD: [Link]
[Link]
The SetAbort method explicity declares that a transaction has not been completed and
prevents resources from being updated.
Code:
------------------------[Link]-------------------
<HTML>
<HEAD>
</HEAD>
<BODY>
<form action="[Link]" method="POST">
ProductID:<input type="Text" name="ProductID">
Product Name:<input type="Text" name="Name">
Quantity Wanted:<input type="Text" name="Order">
<input type="Submit" name="Submit" value="Submit">
</form>
</BODY>
</HTML>
------------------------[Link]-------------------
<%
@Transaction = "Required"
set connDB=[Link]("[Link]")
[Link] "products", "", ""
productID = [Link]("ProductID")
mySQL="Select * from products Where productID = " & productID
Set rsProductSrch = [Link]("[Link]")
[Link] mySQL, connDB, adOpenStatic, adLockPessimistic
If [Link] Or [Link] Then
[Link]
ElseIf [Link]("Quanity") < [Link]("Order") Then
[Link] "There is not enough in stock to give the present order. There are " &
[Link]("Quanity") & "in stock and your order is for " & [Link]("Order") &
".<br>"
[Link]
Else
[Link]("Quanity") = [Link]("Quanity") -
[Link]("Order")
[Link]
[Link]
End If
[Link]
[Link]
%>
Sub OnTransactionAborted()
[Link] "The transaction aborted because there was not enough quantity on hand to
fill your order."
End Sub
Sub OnTransactionCommit()
[Link] "The transaction was committed and your order is being sent."
End Sub
The SetComplete method declares that the transaction of this object has been completed. In
order for a transaction to be successfully completed, all individual components of the
transaction must also be completed and have called SetComplete. By default, a script is
considered to be completed if it runs to conclusion and does not abort. Therefore, in many
cases, it may not be necessary to call SetComplete from the script.
Code:
------------------------[Link]-------------------
<HTML>
<HEAD>
</HEAD>
<BODY>
<form action="[Link]" method="POST">
ProductID:<input type="Text" name="ProductID">
Product Name:<input type="Text" name="Name">
Quantity Wanted:<input type="Text" name="Order">
<input type="Submit" name="Submit" value="Submit">
</form>
</BODY>
</HTML>
------------------------[Link]-------------------
<%
@Transaction = "Required"
set connDB=[Link]("[Link]")
[Link] "products", "", ""
productID = [Link]("ProductID")
mySQL="Select * from products Where productID = " & productID
Set rsProductSrch = [Link]("[Link]")
[Link] mySQL, connDB, adOpenStatic, adLockPessimistic
If [Link] Or [Link] Then
[Link]
ElseIf [Link]("Quanity") < [Link]("Order") Then
[Link] "There is not enough in stock to give the present order. There are " &
[Link]("Quanity") & "."
[Link]
Else
[Link]("Quanity") = [Link]("Quanity") -
[Link]("Order")
[Link]
[Link]
End If
[Link]
[Link]
%>
Sub OnTransactionAborted()
[Link] "The transaction aborted because there was not enough quantity on hand to
fill your order."
End Sub
Sub OnTransactionCommit()
[Link] "The transaction was committed and your order is being sent."
End Sub
Code:
<%
@Transaction=Required Language="VBScript"
[Link] = TRUE
[Link] = 5
%>
<HTML>
<HEAD>
</HEAD>
<BODY>
<%
Do
x=x+1
[Link] x & "<BR>"
Loop While x < 10000
%>
</BODY>
</HTML>
Sub OnTransactionAbort()
[Link] "The transaction aborted because the script ran out of time. This is the
Transaction Abort Handler."
End Sub
Output:
The transaction aborted because the script ran out of time. This is the Transaction Abort
Handler.
EVENT: [Link]
The OnTransactionCommit event occurs when a transaction has been completed. The
OnTransactionCommit event is simply a subroutine with a reserved name that is referenced
by the script. It can contain any script you may wish to run when the transaction is completed.
Code:
<% @Transaction=Required Language="VBScript" %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<%
Do
x=x+1
[Link] x & "<BR>"
Loop While x < 5
%>
</BODY>
</HTML>
Sub OnTransactionCommit()
[Link] "The transaction committed. This is the Transaction Commit Handler."
End Sub
Output:
1
2
3
4
5
The transaction committed. This is the Transaction Commit Handler.
EVENT: Session_OnEnd
The Session_OnEnd event occurs when the Session ends. Normally, a Session is ended by
being timed-out, either by default or by using [Link], or by being abandoned by
using [Link]. The Session_OnEnd event is simply a subroutine with a reserved
name that is placed in the [Link] file. The code in the event cannot affect the user
because he has quit the site.
In the example, there is no output because the user is already gone. The first line must specify
the script language.
Note, only the Application, Server, and Session built-in objects are available from within the
OnEnd event handler.
Code:
-------------------[Link]--------------------------
<script Language="VBScript" RUNAT=Server>
Sub Application_OnEnd()
End Sub
Sub Application_OnStart()
Application("NumSession") = 0
Application("NumVisited") = 0
End Sub
Sub Session_OnEnd()
Application("NumSession") = Application("NumSession") - 1
End Sub
Sub Session_OnStart()
Application("NumSession") = Application("NumSession") + 1
Application("NumVisited") = Application("NumVisited") + 1
End Sub
</script>
-------------------[Link]----------------------------
[Link] "You are " & Application("NumSession") & " of " & Application("NumVisited") &
" users."
EVENT: Session_OnStart
The Session_OnStart event occurs just before the server creates the Session object. The
Session_OnStart event is simply a subroutine with a reserved name that is placed in the
[Link] file. You can place any code you desire inside this subroutine. All of the built-in ASP
objects are available from within the Session_OnStart event handler.
Code:
-------------------[Link]--------------------------
<script Language="VBScript" RUNAT=Server>
Sub Application_OnEnd()
End Sub
Sub Application_OnStart()
Application("NumSession") = 0
Application("NumVisited") = 0
End Sub
Sub Session_OnEnd()
Application("NumSession") = Application("NumSession") - 1
End Sub
Sub Session_OnStart()
Application("NumSession") = Application("NumSession") + 1
Application("NumVisited") = Application("NumVisited") + 1
End Sub
</script>
-------------------[Link]----------------------------
[Link] "You are " & Application("NumSession") & " of " & Application("NumVisited") &
" users."
Output:
You are 1 of 3 users.
PROPERTY: [Link]
The Pics property adds the value of the PICS rating to the pics-label field in the the response
header for a document or a site. This statement must be located before the <HTML> tag. The
PICS label has quotes in the label, and the quotes must be replaced with, & chr(34) &. Or you
can use double quotes.
Using chr(34):
Code:
<% [Link]("(PICS-1.1 <[Link] labels on " & chr(34)
& "1997.01.05R08:15-0500" & chr(34) & " until " & chr(34) & "1999.12.31T23:59-0000" &
chr(34) & " ratings(v 2 s 1 l 2 n 0))")
%>
The QueryString collection property contains, and allows you to retrieve, the values of the
variables in the query string which are the statements that follows a question mark. Many
different processes can produce a query string such as an anchor tag, a form submission, or
typing the string into the address box of the browser.
You can iterate through a collection using a For Each item in ... Next loop.
Variable
The Variable specifies the name of the variable in the query string whose value is to be
retrieved.
Index
The optional Index argument is used when the Variable argument has more than one value. It
is an integer, ranging from 1 to [Link](Variable).Count, which is used to
select values from the Variable. Count is the total number of multiple values.
Code:
-----------------------[Link]----------------------
<HTML>
<HEAD>
</HEAD>
<BODY>
<A HREF="[Link]?language=ASP&type=general">Query sample</A>
</BODY>
</HTML>
-----------------------[Link]----------------------
<%
For Each item In [Link]
[Link](item & " = " & [Link](item) & VbCrLf)
Next
%>
Output:
language = ASP
type = general
METHOD: [Link]
[Link](URL)
The Redirect method stops processing the current script and attempts to connect the client to
a different URL. This is accomplished by adding an HTTP redirection header to the output
stream that is being sent from the server to the client. Unfortunately, if page content has
already been sent to the client and if a proxy server lies between the server and the client, an
error message can be generated. Therefore it is advisable to set [Link] to true and
to call [Link] just before calling Redirect.
Note in ASP 2.0, the buffering default setting is false and in ASP 3.0, the buffering default
setting is true.
URL
The URL argument is the Uniform Resource Locator (URL) that the browser is redirected to.
Code:
--------------[Link]---------------
<% [Link] = true %>
<HTML>
<BODY>
<%
[Link] "This is [Link] and switching to [Link]"
[Link]
[Link] "[Link]"
%>
</BODY>
</HTML>
--------------[Link]-----------------
<HTML>
<BODY>
<%
[Link] "This is [Link]"
%>
</BODY>
</HTML>
Output:
File1 is written and then the browser will load File2:
------------[Link]------------------
This is [Link] and switching to [Link]
------------[Link]-------------------
This is [Link]
OBJECT: Request
The Request object provides access to all of the information that is passed in a request from
the browser to the server. This information is stored among five types of Request collections.
A collection is similar to a data structure or array. Individual items in the collection are
accessed via a unique key assigned to that item.
All variables can be accessed directly by calling Request(variable) without the collection
name. In this case, the Web server searches the collections in the following order:
QueryString, Form, Cookies, ClientCertificate, then ServerVariables.
PROPERTY
TotalBytes Property
The TotalBytes property specifies the total number of bytes sent in the body of the HTTP
request.
COLLECTION PROPERTIES
METHOD
The TotalBytes property is a read-only value that specifies the total number of bytes sent by
the client to the server in the body of the HTTP request.
Code:
-------------------[Link]-----------------
<HTML>
<HEAD>
</HEAD>
<BODY>
<FORM ACTION="[Link]" METHOD="POST">
Name:<INPUT TYPE="Text" NAME="name" MAXLENGTH="30"><BR>
Age: <INPUT TYPE="Text" NAME="age" MAXLENGTH="10"><BR>
Sex: <INPUT TYPE="Text" NAME="sex" MAXLENGTH="10"><BR>
<INPUT TYPE="Submit" NAME="submit" VALUE="submit"><BR>
</FORM>
</BODY>
</HTML>
-------------------[Link]------------------
<%
Dim ByteCount
ByteCount = [Link]
[Link]("ByteCount = " & ByteCount & " bytes")
%>
Output
It is dependent on the data entered into the form.
For example, if Name=Bill, Age=56, and Sex=male.
ByteCount = 39 bytes
COLLECTION PROPERTY: [Link]
Request. ServerVariables (EnvironmentVariable)
The ServerVariables collection property contains, and allows you to retrieve, the values of
server environment variables.
You can iterate through a collection using a For Each item in ... Next loop.
EnvironmentVariable
The EnvironmentVariable argument can be any one of the following forty three variables:
HTTP_COOKIE returns the cookie string that was included with the request.
HTTP_UA_OS returns a string stating the operating system of the user agent.
HTTP_UA_CPU returns a string stating the processor type used by the user
agent.
HTTPS returns ON if the request came in through secure channel or OFF if the
request is through a non-secure channel.
INSTANCE_ID is the ID for the Internet Information Server (IIS) instance in text
format.
LOCAL_ADDR returns the server address on which the request came in.
SERVER_NAME is the server's host name, Domain Name Server (DNS) alias,
or Internet Protocol (IP) address.
Code:
<%
IPAddress = [Link]("REMOTE_ADDR")
Software = [Link]("SERVER_SOFTWARE")
Protocol = [Link]("SERVER_PROTOCOL")
[Link] "Your IP Address is " & IPAddress & " and your server is running " & Software
& " under " & Protocol & "protocol."
%>
Output:
Your IP Address is [Link] and your server is running Microsoft-IIS/4.0 under HTTP/1.1
protocol.
OBJECT: Response
Modified in version 3.0
PROPERTIES
CacheControl Property
The CacheControl property determines whether a proxy server can cache the Active Server
Page.
Charset Property
The Charset property appends the name of the character set being used to the content-type
header contained in the response object.
ContentType Property
The ContentType property specifies the HTTP content type/subtype for the response header.
Expires Property
The Expires property specifies the length of time in minutes until a cached page on the
browser expires.
ExpiresAbsolute Property
The ExpiresAbsolute property specifies a date and time when a cached page on the browser
will expire.
PICS Property
The PICS property specifies the value of a PICS rating label for a document or a site.
Status Property
The Status property specifies the value of the status line returned by the server.
COLLECTION PROPERTIES
METHODS
Clear Method
The Clear method clears (erases) any buffered HTML output.
End Method
The End method causes the web server to stop processing the script and to return the current
results without processing the rest of the file.
Flush Method
The Flush method sends the contents of the buffer.
Code:
<%
IPAddress = [Link]("REMOTE_ADDR")
If IPAddress <> "[Link]" Then
[Link] = "403 Access Forbidden"
[Link] [Link]
[Link]
End If
%>
<HTML>
<HEAD>
</HEAD>
<BODY>
You have accessed this page through the IP Address of [Link]. </BODY>
</HTML>
The output of the above is the following if the IP address of the client is [Link]:
You have accessed this page through the IP Address of [Link].
The Write method writes any specified string to the HTTP output.
Variant
The Variant argument is the data to be written as a string. A variant is a VBScript data type
and includes characters, integers, and strings. The variant cannot contain the character
combination of %>.
Code:
<%
[Link] "Hello World"
[Link] "<BR>"
%>
Output:
Hello World<BR>
PROPERTY: [Link]
The ScriptTimeout property specifies the amount of runtime in seconds for a script before it
terminates. The default value is 90 seconds.
The following code causes a script to timeout if the script takes more than 150 seconds to
complete.
The Server object provides access to the utility functions of the server.
PROPERTY
ScriptTimeout Property
The ScriptTimeout property is the amount of runtime in seconds for a script before it
terminates.
METHODS
[Link] (Path)
The Transfer method allows you to transfer from inside one ASP page to another ASP page.
All of the state information that has been created for the first (calling) ASP page will be
transferred to the second (called) ASP page. This transfered information includes all objects
and variables that have been given a value in an Application or Session scope, and all items
in the Request collections. For example, the second ASP page will have the same SessionID
as the first ASP page.
When the second (called) ASP page completes its tasks, you do not return to the first (calling)
ASP page.
In contrast, the Execute method allows you to call another ASP page, and when the called
page has completed its tasks, you return to the calling ASP page.
Path
The Path argument is a string specifying either the absolute or relative path of the ASP page
being called. The file name must be included in the path. The entire Path must be enclosed
inside a pair of quotes.
Code:
----------[Link]----------
<%
Application("name") = "Application Maker"
Application("publishdate") = "05/15/01"
Application("author") = "DevGuru"
Set Application("Obj1") = [Link]("[Link]")
[Link]("[Link]")
%>
----------[Link]----------
<%;
[Link] "Output from [Link]"
For Each Item in [Link]
If IsObject( [Link](Item)) Then
[Link] Item & " is an object.<BR>"
Else
[Link] Item & "=" & [Link](Item) & "<BR>"
End If
Next
%>
Output:
Output from [Link]
name=Application Maker
publishdate=05/15/01
author=DevGuru
OBJ1 is an object.
METHOD: [Link]
[Link](String)
The URLEncode method takes a string and converts it into a URL-encoded format. For
example, you can use URLEncode to ensure that hyperlinks in your Active Server Pages are
in the correct format.
String
Code:
<% [Link] [Link]("[Link] %>
Output:
http%3A%2F%2Fwww%2Eissi%2Enet
OBJECT: Session
Modified in version 3.0
The first time a user makes a document request, a Session object is assigned to the user and
it is used to store, share, and retrieve information concerning the user session. By default, the
Session object is destroyed after a session has been idle for twenty minutes.
PROPERTIES
CodePage Property
The CodePage property specifies the server codepage that will be used to display dynamic
content.
LCID Property
The LCID property specifies the location identifier that will be used to display dynamic content.
SessionID Property
The SessionID property returns the unique identifier for a user session.
Timeout Property
The Timeout property is the length of time in minutes before an idle session is terminated.
COLLECTION PROPERTIES
METHODS
Abandon Method
The Abandon method terminates a user session, destroys all data and objects in the current
Session object, and releases its resources.
EVENTS
OnEnd Event
The OnEnd event occurs when the Session quits. The signal of this event will run a handler
script in the [Link] file, if the script exists.
OnStart Event
The OnStart event occurs before the start of any new Session by a user. The signal of this
event will run a handler script in the [Link] file, if the script exists.
PROPERTY: [Link]
The SessionID property returns the unique session identifier for the current user. The identifier
is generated by the server and is a Long data type.
Code:
Output:
Your Session ID is 465107831
PROPERTY: [Link]
The Timeout property specifies the number of minutes that can elapse while a session is idle
before it is terminated. The default is 20 minutes. If the user does not refresh the page or
request another page within the allotted time, the session is automatically terminated and the
resources are released.
The following code causes the session to terminate if the session is idle for more than 35
minutes.
The StaticObjects collection property contains a list of all of the items that have been created
and added to the Session object using the HTML <OBJECT> tag.
You can iterate through a collection using a For Each item in ... Next loop.
Key
Code:
----------[Link]-------------
<OBJECT RUNAT=Server SCOPE=Session ID=MyInfo PROGID="[Link]">
</OBJECT>
-----------[Link]-----------------
<%
For Each Item In [Link]
[Link] Item & "<BR>"
Next
%>
Output:
MyInfo
MyConnection
MyADRot