Using the ASP Intrinsics

From RAD Studio
Jump to: navigation, search

Go Up to Creating Active Server Pages - Overview


The ASP intrinsics are a set of COM objects supplied by ASP to the objects running in an Active Server Page. They let your Active Server Object access information that reflects the messages passing between your application and the Web browser, as well as a place to store information that is shared among Active Server Objects that belong to the same ASP application.

To make these objects easy to access, the base class for your Active Server Object surfaces them as properties. For a complete understanding of these objects, see the Microsoft documentation. However, the following topics provide a brief overview.

Application

The Application object is accessed through an IApplicationObject interface. It represents the entire ASP application, which is defined as the set of all .asp files in a virtual directory and its subdirectories. The Application object can be shared by multiple clients, so it includes locking support that you should use to prevent thread conflicts.

IApplicationObject includes the following:

IApplicationObject interface members :

Property, Method, or Event Meaning

Contents property

Lists all the objects that were added to the application using script commands. This interface has two methods, Remove and RemoveAll, that you can use to delete one or all objects from the list.

StaticObjects property

Lists all the objects that were added to the application with the <OBJECT> tag.

Lock method

Prevents other clients from locking the Application object until you call Unlock. All clients should call Lock before accessing shared memory (such as the properties).

Unlock method

Releases the lock that was set using the Lock method.

Application_OnEnd event

Occurs when the application quits, after the Session_OnEnd event. The only intrinsics available are Application and Server. The event handler must be written in VBScript or JScript.

Application_OnStart event

Occurs before the new session is created (before Session_OnStart). The only intrinsics available are Application and Server. The event handler must be written in VBScript or JScript.



Request

The Request object is accessed through an IRequest interface. It provides information about the HTTP request message that caused the Active Server Page to be opened.

IRequest includes the following:

IRequest interface members :

Property, Method, or Event Meaning

ClientCertificate property

Indicates the values of all fields in the client certificate that is sent with the HTTP message.

Cookies property

Indicates the values of all Cookie headers on the HTTP message.

Form property

Indicates the values of form elements in the HTTP body. These can be accessed by name.

QueryString property

Indicates the values of all variables in the query string from the HTTP header.

ServerVariables property

Indicates the values of various environment variables. These variables represent most of the common HTTP header variables.

TotalBytes property

Indicates the number of bytes in the request body. This is an upper limit on the number of bytes returned by the BinaryRead method.

BinaryRead method

Retrieves the content of a Post message. Call the method, specifying the maximum number of bytes to read. The resulting content is returns as a Variant array of bytes. After calling BinaryRead, you can't use the Form property.



Response

The Request object is accessed through an IResponse interface. It lets you specify information about the HTTP response message that is returned to the client browser.

IResponse includes the following:

IResponse interface members :

Property, Method, or Event Meaning

Cookies property

Determines the values of all Cookie headers on the HTTP message.

Buffer property

Indicates whether page output is buffered When page output is buffered, the server does not send a response to the client until all of the server scripts on the current page are processed.

CacheControl property

Determines whether proxy servers can cache the output in the response.

Charset property

Adds the name of the character set to the content type header.

ContentType property

Specifies the HTTP content type of the response message's body.

Expires property

Specifies how long the response can be cached by a browser before it expires.

ExpiresAbsolute property

Specifies the date and time when the response expires.

IsClientConnected property

Indicates whether the client has disconnected from the server.

Pics property

Set the value for the pics-label field of the response header.

Status property

Indicates the status of the response. This is the value of an HTTP status header.

AddHeader method

Adds an HTTP header with a specified name and value.

AppendToLog method

Adds a string to the end of the Web server log entry for this request.

BinaryWrite method

Writes raw (uninterpreted) information to the body of the response message.

Clear method

Erases any buffered HTML output.

End method

Stops processing the .asp file and returns the current result.

Flush method

Sends any buffered output immediately.

Redirect method

Sends a redirect response message, redirecting the client browser to a different URL.

Write method

Writes a variable to the current HTTP output as a string.



Session

The Session object is accessed through the ISessionObject interface. It allows you to store variables that persist for the duration of a client's interaction with the ASP application. That is, these variables are not freed when the client moves from page to page within the ASP application, but only when the client exits the application altogether.

ISessionObject includes the following:

ISessionObject interface members :

Property, Method, or Event Meaning

Contents property

Lists all the objects that were added to the session using the <OBJECT> tag. You can access any variable in the list by name, or call the Contents object's Remove or RemoveAll method to delete values.

StaticObjects property

Lists all the objects that were added to the session with the <OBJECT> tag.

CodePage property

Specifies the code page to use for symbol mapping. Different locales may use different code pages.

LCID property

Specifies the locale identifier to use for interpreting string content.

SessionID property

Indicates the session identifier for the current client.

TimeOut property

Specifies the time, in minutes, that the session persists without a request (or refresh) from the client until the application terminates.

Abandon method

Destroys the session and releases its resources.

Session_OnEnd event

Occurs when the session is abandoned or times out. The only intrinsics available are Application, Server, and Session. The event handler must be written in VBScript or JScript.

Session_OnStart event

Occurs when the server creates a new session is created (after Application_OnStart but before running the script on the Active Server Page). All intrinsics are available. The event handler must be written in VBScript or JScript.



Server

The Server object is accessed through an IServer interface. It provides various utilities for writing your ASP application.

IServer includes the following:

IServer interface members :

Property, Method, or Event Meaning

ScriptTimeOut property

Same as the TimeOut property on the Session object.

CreateObject method

Instantiates a specified Active Server Object.

Execute method

Executes the script in a specified .asp file.

GetLastError method

Returns an ASPError object that describes the error condition.

HTMLEncode method

Encodes a string for use in an HTML header, replacing reserved characters by the appropriate symbolic constants.

MapPath method

Maps a specified virtual path (an absolute path on the current server or a path relative to the current page) into a physical path.

Transfer method

Sends all of the current state information to another Active Server Page for processing.

URLEncode method

Applies URL encoding rules, including escape characters, to a specified string



See Also