03 - Traditional ASP Concepts

3.1 Introduction of ASP

Active Server Pages is the abbreviation of ASP. It is a Microsoft technology that enables the development of dynamic web pages. ASP files contain HTML, text, XML and scripts used for developing web pages. These tags provide dynamic content for web development. An ASP file has .asp file extension. ASP programs runs inside Internet Information Services (IIS).

Active Server Pages enables server side scripting for IIS. It provides native support for both VBScript and Jscript. Server executes the scripts present in the ASP files.

Advantages of using ASP

  • User can dynamically edit, change, or update the content of a web page
  • No client side constraints are necessary for developing the ASP application
  • It helps user access any database and send the results to the web browser
  • It provides security as the ASP code cannot be viewed from the web browser
  • ASP programming minimizes the network traffic
  • It responds the user queries, data submitted from the HTML forms
  • Web pages can be customized for better individual use
  • ASP is simple to use and the development time is saved.

3.2 Working of ASP

The web architecture of ASP is represented. The client/user send the HTTP request to the IIS for processing the ASP page. IIS identifies the scripting language used for developing the ASP page. Depending on the scripting language, the file is sent to the ActiveX scripting engine. The engine performs the  operations and the result is sent back to the IIS. The interchange server checks for the data objects present in the page.

The objects are transferred to the ActiveX Data objects. Active objects are sent to the database for performing the database operations. The database sends the result to the data objects. IIS receives the expected result through database. IIS send the result back to the client/user through the HTTP response object. Thus, this is the execution cycle of the ASP

3.3 ASP Objects

There are several ASP objects used for writing ASP code. Each object has its unique functionality. The list of ASP objects is mentioned below:

  • ASP Response object
  • ASP Request object
  • ASP application object
  • ASP session object
  • ASP error object
  • ASP FileSystem object
  • ASP TextStream object
  • ASP Drive object
  • ASP File object
  • ASP Folder object
  • ASP Dictionary

1) ASP Response object:

The ASP Response object is used to send the server output to the user. The properties and methods of the ASP Response object with their syntax are mentioned below:

Properties of ASP Response object

Property

Description

Syntax

Buffer

It is used to specify that the page can be buffered

response.Buffer[=flag], where flag is Boolean value.

CacheControl

It is used to cache the output generated by ASP page through proxy server

response.CacheControl[=control_header],

where control header value can be private or public

Charset

It appends the name of character set to the content header in Response object

response.Charset(charsetname), where charset is string that specifies a character set on the page

ContentType

It sets the HTTP content type for the Response object

response.ContentType[=contenttype], where contentype is string variable

Expires

It defines the duration of page caching before the browser expires

response.Expires[=number], where number is minutes before the page expires

ExpiresAbsolute

It sets the date and time for a cached page to expire on the browser

response.ExpiresAbsolute[=[date][time]],

where date and time are values when the page will expire

IsClientConnected

It indicates whether the client is disconnected from the browser

response.IsClientConnected

Status

It specifies the value of the status line returned by server

response.Status=statusdescription,

where status description is a three digit code

Property of ASP Request object

Property

Description

Syntax

TotalBytes

It returns the total number of bytes the client sent in the request body

varbytes=Request.TotalBytes

Method of ASP Request object

Method

Description

Syntax

BinaryRead

It is used to retrieve the data sent to the server

Request.BinaryRead(count), where count is the number of bytes to be read from client

Collections of ASP Request object

Collection

Description

Syntax

ClientCertificate

It contains the field values stored in the client certificate

 

Cookies

It is used to get or set cookie values

Response.Cookies(name)[(key)|.attribute]

=value

Form

It is used to retrieve the values of form elements

Request.Form(element)[(index)|.Count]

QueryString

It contains all the variable in HTTP query string

Request.QueryString(variable)[(index)|

.Count]

ServerVariables

It contains all the server variables

Request.ServerVariables(server_variable)

3) ASP Application object:

The application consists of many ASP files. The purpose of the Application object is to combine these files together. The Application object stores variables from the ASP pages. Only one application object is used among all the users. The information stored in the Application object can be accesses from any page. The Application objects collections, events and methods are mentioned below:

Collections of ASP Application object:

Collection

Description

Syntax

Contents

It contains all the items appended to the application through script command

Application.Contents(Key),

where key is the name of the item to retrieve

StaticObjects

It contains all the objects appended to the application with HTML <object> tag

Application.StaticObjects(Key),

where key is the name of the item to retrieve

 Methods of ASP Application object

Method

Description

Syntax

Contents.Remove

It deletes an item from the Content collection

Application.Contents.Remove

(name|index), conatins the value to retrieved

Contents.RemoveAll()

It removes all items from the Content collection

Appliations.Content.RemoveAll()

Lock

It prevents the user from modifying the variable

Application.Lock

Unlock

It helps user to modify the variable

Application.Unlock

Events of ASP Application object:-

Event

Description

Syntax

Application_OnStart

It occurs before the first session is created

Application_OnStart

Application_OnEnd

It occurs when the application ends

Application_OnEnd

4) ASP Session object:

The session object is used to store information about the user session. A cookie is created for every user. The cookie contains all the information required for user identification. The interface providing this feature is session object. 
The collections, properties, methods and events of the ASP Session object are mentioned below:

Collections of ASP Session object

Collection

Description

Syntax

Contents

It contains items appended to the session through command object

Session.Contents(Key),

Where Key is the name of the item to be retrieved

StaticObjects

It contains all the objects appended to the session through HTML <object> tag

Application.StaticObjects(Key),

Where Key is the name of the item to be retrieved

Properties of ASP Session object

Property

Description

Syntax

CodePage

It specifies the character set used to display dynamic content

Session.CodePage(=CodePage),

Where CodePage is for the system running the script

LCID

It sets or returns an integer specifying location or region

Session.LCID(=LCID), where

LCID is a locale identifier

SessionID

It returns a unique id for each user

Session.SessionID

Timeout

It sets or returns the timeout period for the session object

Session.Timeout[=nMinutes]

Methods of ASP Session object

Method

Description

Syntax

Abandon

It destroys the user session

Session.Abandon

Contents.Remove

It deleted the item from the Contents collection

Session.Contents.Remove

(name|index)

Contents.RemoveAll()

It deleted all the items from the Contents collection

Session.Contents.RemoveAll()

Events of ASP Session object

Event

Description

Syntax

Session_OnStart

It occurs when the server creates a session

Session_OnStart

Session_OnEnd

It occurs when the session ends

Session_OnEnd

5) ASP Server object

The ASP Server object is used to access the properties and methods on the server. The properties and methods of the ASP Server object are mentioned below

Property of ASP Server object

Property

Description

Syntax

ScriptTimeout

It sets or returns the maximum number of seconds a script can execute

Server.ScriptTimeout

[=NumSeconds]

Methods of ASP Server object

Method

Description

Syntax

CreateObject

It creates an instance of an object

Server.CreateObject(progID),

where progID is the object type to be created

Execute

It executes the ASP file from another ASP file

Server.Execute(path), where path is the location of the ASP file

GetLastError()

It returns an ASPError object for the error condition

Server.GetLastError()

HTMLEncode

It applies HTML encoding to a string

Server.HTMLEncode(string),

where string is to be encoded

MapPath

It maps a specified path to the physical path

Server.MapPath(path),

where path is relative or virtual

Transfer

It sends information from ASP file to another file

Server.Transfer(path),

where path is the location of the ASP file

URLEncode

It applies the URL encoding rules to the specified string

Server.URLEncode(string),

Where the string is to encoded

6) ASP Error object

The ASP Error object is used to display detail information of error occurring in the ASP page. The properties of the ASP Error object is mentioned below

Properties of ASP Error object

Property

Description

Syntax

ASPCode

It returns an error code generated by IIS

ASPError.ASPCode()

ASPDescription

It returns a detail description of the error

ASPError.ASPDescription()

Category

It returns the source of the error

ASPError.Category()

Column

It returns the column position within the ASP file

ASPError.Column()

Description

It returns a short description of the error

ASPError.Description()

File

It returns the name of the ASP file generating the error

ASPError.File()

Line

It returns the number of lines that generated the error

ASPError.Line()

Number

It returns the standard COM error code for the error

ASPError.Number()

Source

It returns the actual source code of the line

ASPError.Source()

7) ASP FileSystem object

The ASP FileSystem object is used to access the file system on a server. These objects can manipulate files, folders, and directory paths. File system information can be retrieved using the FileSystem object. The properties and methods of the FileSystem object are mentioned below

Property of ASP FileSystem object

Property

Description

Syntax

Drives

It returns a collection of drive objects on the system

[drivecol1=]FileSystemObject.Drives

Methods of ASP FileSystem object

Method

Description

Syntax

BuildPath

It appends a name to an existing path

[newpath=]FileSystemObject.

BuildPath(path,name)

CopyFile

It copies one or more files from one location to another

FileSystemObject.CopyFile

source, destination[,overwrite]

CopyFolder

It copies one or more folder in the system

FileSystemObject.CopyFolder

Source, destination[,overwrite]

CreateFolder

It creates a new folder

FileSystemObject.CreateFolder

(name)

CreateTextFile

It creates a new text file in the current folder

FileSystemObject.CreateTextFile

(filename[,overwrite[,Unicode]])

DeleteFile

It deleted the file specified in the parameters list

FileSystemObject.DeleteFile(

Filename[, force])

DeleteFolder

It deleted the folders specified in the parameter list

FileSystemObject.DeleteFolder(

Foldername[, force])

DriveExists

It checks for the existence of the specific drive

FileSystemObject.DriveExists(

drive)

FileExists

It checks for the existence of the specific file

FileSystemObject.FileExists(

filename)

FolderExists

It checks for the existence of the specific folder

FileSystemObject.FolderExists(

foldername)

GetAbsolutePathName

It returns the complete path from to root to the destination

FileSystemObject.GetAbsolutPath

Name(path)

GetBaseName

It returns the base name of the file or folder

FileSystemObject.GetBaseName

(path)

GetDrive

It returns the drive object for the specific parameter

FileSystemObject.GetDrive

(drivespec)

GetDriveName

It returns the drive name of the specific path

FileSystemObject.GetDriveName

(path)

GetExtensionName

It returns the file extension name for the component

FileSystemObject.GetExtension

Name(path)

GetFile

It returns the file object for the specified path

FileSystemObject.GetFile(path)

GetFileName

It returns the file or folder for the last component in the specified path

FileSystemObject.GetFileName

(path)

GetFolder

It returns the folder object for the specific path

FileSystemObject.GetFolder

(path)

GetParentFolder

It returns the name of the parent folder in the specific path

FileSystemObject.GetParent

FolderName(path)

GetSpecialFolder

It returns the path of Windows special folders

FileSystemObject.GetSpecial

Folder(foldername)

GetTempName

It returns a randomly generated temporary file

FileSystemObject.GetTemp

Name

MoveFile

It moves files to different location

FileSsyetnObject.MoveFile

Source, destination

MoveFolder

It moves folders to different location

FileSystenObject.MoveFolder

Source, destination

OpenTextFile

It opens the specific file and returns the TextStream object

FileSystemObject.OpenTextFile

(fname, mode, create, format)

8) ASP TextStream object

The ASP TextStream object is used for accessing the contents of the text file. The CreateTextFile or OpenTextFile methods are used to create the instance of the TextStream object. The properties and methods of the ASP TextSteam object are as mentioned below

Properties of ASP TextStream object

Property

Description

Syntax

AtEndOfLine

It returns Boolean value depending on the file pointer position

TextStreamObject.

AtEndOfLine

AtEndOfStream

It returns true if the file pointer is at the end of the file

TextStreamObject.

AtEndOfStream

Column

It returns the column number of the current character position

TextStreamObject.

Column

Line

It returns the current line number in the file

TextStreamObject.Line

Methods of ASP TextStream object

Method

Description

Syntax

Close

It closes the TextStream file

TextStreamObject.Close

Read

It reads the specific number of characters from the file

TextStreamObject.Read

(numchar)

ReadAll

It reads the complete TextStream file

TextStreamObject.ReadAll

ReadLine

It reads one line from the TextStream file

TextStreamObject.ReadLine

Skip

It skips the number of characters specified while reading the file

TextStreamObject.Skip

(numchar)

SkipLine

It skips a line while reading a TextStream file

TextStreamFile.SkipLine

Write

It writes the specific text to the TextStream file

TextStreamObject.Write

(text)

WriteLine

It writes the specific text and an new line character

TextStreamObject.WriteLine

(text)

WriteBlankLines

It writes the specific number of new line character to the file

TextStreamObject.Write

BlankLines(numlines)

9) ASP Drive object

The ASP Drive object is used to return information about network share or local drive. The information regarding driver type, free space, serial number, volume name is specified in the Drive object.

Properties of ASP Drive object

Property

Description

Syntax

AvailableSpace

It returns the space available for the user

DriveObject.AvailableSpace

DriveLetter

It returns the letter indicating the local drive

DriveObject.DriveLetter

DriveType

It returns the value indicating the drive type

DriveObject.DriveType

FileSystem

It returns the file system in use for the specific drive

DriveObject.FileSystem

FreeSpace

It returns the amount of free space for the user

DriveObject.FreeSpace

IsReady

It returns true if the specified drive is ready

DriveObject.IsReady

Path

It returns the path for a specific drive, file or folder

DriveObject.Path, FolderObject.Path

FileObject.Path

RootFolder

It returns the root folder of the specific drive

DriveObject.RootFolder

SerialNumber

It returns the serial number of the specific drive

DriveObject.SerialNumber

ShareName

It returns the network share name for the specific drive

DriveObject.ShareName

TotalSize

It returns the total size, in bytes for specific drive

DriveObject.TotalSize

VolumeName

It returns the volume name of the specific drive

DriverObject.VolumeName

[=newname]

10) ASP File object

The ASP File object is used to return information for the specified file. User must create an instance of the File object through FileSystemObject. Next, instantiate the File object through the GetFile method. The properties and methods of the ASP File object are mentioned below

Properties of ASP File object

Property

Description

Syntax

Attributes

It sets or returns the attributes of a specific file

FileObject.Attributes

[=newattributes]

DateCreated

It returns the date and time of the file creation

FileObject.DateCreated

DateLastAccessed

It returns the date and time when the file was last accessed

FileObject.DateLastAccessed

DateLastModified

It returns the date and time when the file was last modified

FileObject.DateLastModified

Drive

It returns the drive letter of the drive where the file is located

FileObject.Drive

Name

It is used to set or return the name of the specific file

FileObject.Name

[=newname]

ParentFolder

It is used to return the folder object for the parent of the file

FileObject.ParentFolder

Path

It returns the path for the specified file

FileObject.Path

ShortName

It is used for returning short name of the specific file

FileObject.ShortName

ShortPath

It is used for returning short path of the specific file

FileObject.ShortPath

Size

It returns the size of the file in bytes

FileObject.Size

Type

It returns the type of the specific file

FileObject.Type

Methods of ASP File object

Method

Description

Syntax

Copy

It copies the file from the defined location

FileObject.Copy

(destination[, overwrite])

Delete

It deleted the specified file

FileObject.Delete[(force)]

Move

Moves the specified file in the system

FileObject.Move

(destination)

OpenAsTextStream

It opens a specific file and returns the TextStream object

FileObject.OpenAsText

Steam(mode, format)

11) ASP Folder object

The ASP Folder object is used to return information about the folder specified by the user. User must create an instance of the Folder object through FileSystemObject. Next, instantiate the Folder object through the GetFolder method. The collections, properties and methods of the ASP Folder object are mentioned below

Collections of ASP Folder object

Collection

Description

Syntax

Files

It returns the collection of all files in the specific folder

FolderObject.Files

SubFolders

It returns the collection of all subfolders in the specific folder

FolderObject.SubFolders

Properties of ASP Folder object

Property

Description

Syntax

Attributes

It sets or returns the value for a specific folder

FolderObject.Attributes

[=newattributes]

DateCreated

It returns the date and time of the folder creation

FolderObject.DateCreated

DateLastAccessed

It returns the date and time when the folder was last accessed

FolderObject.DateLastAccessed

DateLastModified

It returns the date and time when the folder was last modified

FolderObject.DateLastModified

Drive

It returns the drive letter of the drive where the folder is located

FolderObject.Drive

IsRootFolder

It returns true if the specified folder is root

FolderObject.IsRootFolder

Name

It is used to set or return the name of the specific folder

FolderObject.Name

[=newname]

ParentFolder

It is used to return the folder object for the parent of the folder

FolderObject.ParentFolder

Path

It returns the path for the specified folder

FolderObject.Path

ShortName

It is used for returning short name of the specific folder

FolderObject.ShortName

Size

It returns the size of the folder in bytes

FolderObject.Size

Type

It returns the type of the specific folder

FolderObject.Type

ShortPath

It is used for returning short path of the specific folder

FolderObject.ShortPath

Methods of ASP Folder object

Method

Description

Syntax

Copy

It copies the folder from the defined location

FolderObject.Copy

(destination[, overwrite])

Delete

It deleted the specified folder

FolderObject.Delete[(force)]

Move

Moves the specified folder in the system

FolderObject.Move

(destination)

CreateTextFile

It creates a new text file in the current folder and returns a TextStream object

FolderObject.CreateTextFile

(filename[,overwrite[, Unicode]])

12) ASP Dictionary object

The Dictionary object is used for storing information in name/value pair. The items in the Dictionary objects are identified through keys. Items automatically shift up when the item is deleted from the Dictionary. Dictionary has built in functions that provide easy processing. The properties and methods of the ASP Dictionary object are as mentioned below:

Properties of ASP Dictionary object

Property

Description

Syntax

CompareMode

It sets or returns the comparison mode for comparing keys in Dictionary

DictionaryObject.Compare

Mode[=compare]

Count

It returns the number of key/item pair in the object

DictionaryObject.Count

Item

It sets or returns the value of an item

DictionaryObject.Item

(Key)[=newitem]

Key

Used to set the new value for an existing key value

DictionaryObject.Key(key)

=newkey

Methods of ASP Dictionary object

Method

Description

Syntax

Add

It adds a new key/item pair

to a Dictionary object

DictionaryObject.Add

(key, item)

Exists

It returns a Boolean value if the key exists

DictionaryObject.Exists

(key)

Items

It returns an array of all items in the Dictionary object

DictionaryObject.Items

Keys

It returns an array of all keys in the Dictionary object

DictionaryObject.Keys

Remove

It removes one specific item from the key/item pair

DictionaryObject.Remove

(key)

RemoveAll

It removes all key/item pairs in the Dictionary object

DictionaryObject.RemoveAll

3.4 Sample Program of ASP

3.4.1 Basic syntax of ASP

The ASP code is written by using HTML tags. It contains server scripts inside delimiters. The delimiters are denoted as <% and %>. The scripts are executed on the server and contains expressions, statements, procedures, and operators for the respective scripting language.

The response.write command is used to write output to the browser. The example of the response.write command is mentioned below:

<html>
 <body>
  <%
   response.write(“Welcome to ASP”)
  %>
 </body>
</html>

3.4.2 ASP Procedures

The ASP Procedures are created using the sub keyword. The end of the procedure is defined by end sub keyword. The example of ASP Procedure is mentioned below:

<html>
 <head>
  <%
    sub adproc ( a,b )
    response.write(a+b)
    end sub
  %>
 </head>
 <body>
  <p>Output : <%call adproc ( 2,3 ) %></p>
 </body>
</html>

3.4.3 ASP Functions

User should insert <%@language=”javascript”%> line before the <html> tag. The function keyword is used for creating ASP functions. The example of ASP function is mentioned below:

<%@language =”javascript %>
<html>
 <head>
  <%
    function divno(no1, no2)
    {
    Response.Write(no1/no2)
    }
   %>
 </head>
 <body>
   <p>Output : <%divno(4,6)%></p>
 </body>
</html>

3.4.4 ASP Forms and User Input

Information from the ASP forms can be retrieved using Request objects. The Request.QueryString and Request.Form commands are used to retrieve the form values.

Request.QueryString: The command is used to collect values in a form with the ‘get’ method. Information sent from a form through the get method is visible to all the users. The example of HTML form is shown below:

<form method=”get” action=”Academic.asp”>
 Course:<input type=”text” name=”MCA”><br>
 Grade: <input type=”text” name=”A” ><br><br?
 <input type=”submit” value=”Submit”>
</form>


The script in the Academic.asp is mentioned below:

<body>
 Report Page
 <%
    response.write(request.querystring(“MCA”))
    response.write( “ “ & request,querystring(“A”))
 %>
</body>

The output will be displayed as :

Report Page MCA A

Request.Form: The command is used to collect values using post method from a form. Information sent through the post method is invisible to other users. Unlimited data can be sent through the method. The script in the Academic script is mentioned below

<body>
Report Page
 <% 
    response.write(request.form(“course”))
    response.write(“ “ & request.form(“A”) )
 %>
</body>

3.3.5 ASP Cookies

A cookie is a file embedded by the server on the users system. It is used to identify the user. For every web page request, a cookie is sent to the server. Using ASP, user can create and retrieve cookie values.

The Response.Cookies command is used to create cookies. The example of  cookie creation is mentioned below:

<%
    Response.Cookies(“City”) = “London”
%>

To retrieve the cookie values use the Request.Cookies command. The example to retrieve cookie values is shown below:

<%
   cname = Request.Cookies(“Country”)
   response.write(“Countryname=” & cname)
%>

When the cookie has multiple values , the cookie has Keys. The example of cookie collection as data is mentioned below:

<%
  Response.Cookies(“data”)(“Course”)=”MBA”
  Response.Cookies(“data”)(“Grade”)=”A”
  Response.Cookies(“data”)(“city”)=”London”
  Response.Cookies(“data”)(“country”)=”UK”
%>

Like us on Facebook