The following is the ASP Cheat Sheet
Application Object
Sum of all files that can be accessed through a virtual directory/subdirectory. Initialized when a user accesses any file.
GLOBAL.ASA file provides a place to create variables and objects that have application level scope. Started by the OnStart method of the app object.
Defualt scope for a variable is Page level. Session scope has the best scale.
COLLECTIONS:
Contents - contents.item("ItemName") = "name"
dim myVar = application.contents.item("ItemName")
or
dim myVar = application.contents.item(1)
The first element is 1 not 0
contents.remove
contents.removeall
StaticObjects
METHODS:
lock - Locks all variables in place
unlock
EVENTS:
onend
onstart
ASPError Object
IIS 5.0 automatically calls the GetLastError method by the Server.Transfer method
PROPERTIES:
ASPCode - Holds a numeric code for the error
ASPDescription - String description for the error
Category - String for the category of the error
Column - Number of type Long that is specific to the character of the error
Description - A more descriptive string description for the error
File - Path of the file containing the error
Line - A number of type Long that is specific to the line number of the error
Number - Holds a numeric COM code for the error
Source - String of the line of code that caused the error
On Error Resume Next - only preprocessing and syntax errors will call the server.transfer method to be called. Runtime errors will not be caught, so avoid using it if you can.
ObjectContext Object
This is the root object from which all ASP objects are created. It was introduced in ASP 2.0. Then used as a default, built-in object in ASP
3.0. METHODS:
setAbort
setComplete
EVENTS:
onTransactionAbort
onTransactionCommit - Creates transactional scripts
<%@TRANSACTION = Required %>
Only database transactions are supported.A transaction can only span one ASP page.
Request Object
Forms submit to the HTTP header information using the GET and POST methods of HTTP
PROPERTIES:
totalBytes - total number of bytes posted to the web server request.totalbytes
COLLECTIONS:
clientCertification - You need to enable IIS to accept, require, or ignore client certificates in order to use this.
Digital certificate info
.item = returns the element
.key(3)
.key("string")
.key("certificate") = contains binary stream of certificate
.key("flags") = contains integer values representing constraints
.key("issure") = string of information of subfields (C=US) direct is .key("issureC")
.key("serialnumber") = ASCII hex of client serial number
.key("subject") = similar to issuer
.key("validform") = date/time the certificate is valid
.key("validuntil")
Cookies
HTTP header
Set-Cookie: NAME=VALUE; EXPIRES=DATE; domain=DOMAIN_NAME;
path=PATH; secure
form
.item("string")
.key(3)
.count
queryString = url params
.item
.key
.count
delineate params, ? delineates beginning of querystring, % encoding the string, + spaces
serverVariables
.item
.key
ALL_HTTP - contains all headers
ALL_RAW - contains config info
ALL_MD_PATH - meta-path for the ISAPI DLL/LM/ROOT
ALL_PHYSICAL_PATH - conversion of ALL_MD_PATH c:\inetpub\wwwroot\
AUTH_PASSWORD -
AUTH_TYPE - auth method used
AUTH_USER -
CERT_COOKIE - unique ID for certificate
CERT_FLAGS - either 0 = invalid cert (ceUnrecognizedIssuer) or 1 = valid (ceCertPresent)
CERT_ISSUER - comma delimited string
CERT_KEYSIZE - number of bits used in cert key
CERT_SECRETKEYSIZE - number of bits used in cert private key
CERT_SERIALNUMBER - cert serial number
CERT_SERVER_ISSUER - issuer of cert
CERT_SERVER_SUBJECT - subject field of the server cert
CERT_SUBJECT - subject field of the client cert
CONTENT_LENGTH -
CONTENT_TYPE -
GATEWAY_INTERFACE - the CGI (Common Gateway Interface) used
HTTP_[headername] - retrieve the name of the header
HTTP_ACCEPT - value of the Accept header
HTTP_ACCEPT_LANGUAGE - string describing the language to use for displaying content
HTTP_COOKIE - cookie string included with the request
HTTP_REFERER - string containing the URL of the page that referred the request to the current page using an <a> tag. If the page is redirected, HTTP_REFERER is empty
HTTP_USER_AGENT - string describing the browser that sent the request
HTTPS - Returns ON if the request came in through secure channel or OFF if the request came in through a non-secure channel
HTTPS_KEYSIZE - number of bits in Secure Sockets Layer connection key size
HTTPS_SECRETKEYSIZE - number of bits in server certificate private key
HTTPS_SERVER_ISSUER - issuer field of the server certificate
HTTPS_SERVER_SUBJECT - subject field of the server certificate
INSTANCE_ID - The ID for the IIS instance in text format
INSTANCE_META_PATH - The meta base path for the instance of IIS that responds to the request
LOCAL_ADDR - server address on which the request came in
LOGON_USER - Windows account that the user is logged into
PATH_INFO - Returns extra path information as given by the client
PATH_TRANSLATED - A translated version of PATH_INFO that takes the path and performs any necessary virtual-to-physical mapping
QUERY_STRING - query information stored in the string following the question mark (?) in the HTTP request
REMOTE_ADDR - IP address of the remote host making the request
REMOTE_HOST - name of the host making the request
REMOTE_USER - Returns an unmapped user-name string sent in by the user
REQUEST_METHOD - method used to make the request
SCRIPT_NAME - virtual path to the script being executed
SERVER_NAME - server's host name, DNS alias, or IP address as it would appear in self-referencing URLs
SERVER_PORT - port number to which the request was sent
SERVER_PORT_SECURE - string that contains 0 or 1. If the request is being handled on the secure port, it will be 1. Otherwise, it will be 0
SERVER_PROTOCOL - name and revision of the request information protocol
SERVER_SOFTWARE - name and version of the server software that answers the request and runs the gateway
URL - base portion of the URL
.count
METHODS:
binaryRead - reads a number of bytes from the HTTP request body
mysafearray - name of array used to store the data
bytecount - number of bytes read
Response Object
PROPERTIES:
.buffer - if buffer = TRUE then all scripts run before the results are sent to the client default is FALSE
.cacheControl - if your page is large and doesn't change often, setting this to PUBLIC allows proxy servers to cache your page. Default is PRIVATE
.charset - specify a char set for your page
.contentType - text/plain, text/xml, text/html or richtext, multipart/mixed, alternative, parallel, digest, message/partial, external-body, image/jpeg, gif, audio/basic, video/mpeg, application/ODA, postscript, active. Ex: response.conntenttype = "image/jpeg" for images
.expires - length of time in minutes that it takes for the page to expire out of the client browser cache
.expiresAbsolute - specify a date/time when the page will expire Ex: response.expiresabsolute = #May 7, 2001 21:00:00#
.isClientConnected - read-only property TRUE if client is connected. good to use this around long scripts if the client leaves it will free up server time.
.PICS - Platform for Internet Content Selection. This system helps rating systems like NetNanny.
<http://www.rsac.org/>
.status - 3 digit code and short explanation
1xx sending information
2xx send is successful
3xx redirection of the client
4xx client error ie 404 Not Found
5xx server error i.e. 503 Service Not Available
COLLECTIONS:
.cookies
.item
.key
.count
METHODS:
.addHeader - add your own response header "Name of header", "Value of header"
.appendToLog - add an 80 character string to the server log
.binaryWrite - if you are writing binary data to the client using this will ensure the data is not converted
.clear - empties the response buffer
.end - ends all transfer of information and sends the current amount to the client
.flush - this will result in an runtime error unless response.buffer = true
.redirect - redirect the client to another URL
.write - write information
Server Object
PROPERTIES:
.scriptTimeout - specify the max time in seconds for a page to process. Default is 90 seconds.
METHODS:
.createObject - instantiate an object on the server. The DLL's must be installed on the server for this to work.
.execute - call other ASP script within an ASP script
.getLastError - display information about the error that your script caused
.HTMLEncode - <BR> gets transformed in the browser to a line break. Ex: server.htmlencode("<BR>") will not be transformed
.MapPath - determine the physical path
.transfer - redirect execution of one script to another
.URLEncode - encode a string to be sent in the URL
Session Object
User specific information.
PROPERTIES:
.codePage - Integer that will display content character set 1252 English
.lcID - Local ID, user preference on how info is to be formatted
.sessionID - read-only type long ID for a session
.timeout - Length of time in minutes for the session to be active, default is 20 min.
COLLECTIONS:
.contents - all objects and variables added
.item
.key
.count
.remove
.removeall
.staticObjects
.item
.key
.count
METHODS:
.abandon - releases memory
EVENTS:
.session_OnEnd
.session_OnStart
PRE-PROCESSING DIRECTIVES
<%@ CODEPAGE=1252%> code page for English
or
<%@ LCID=1252%> code page for English
<%@ ENABLESESSIONSTATE=True%> session info is stored
<%@ LANGUAGE="VBScript"%> default language
<%@ TRANSACTION=Required%> - script requires a transaction
<%@ TRANSACTION=Required_New%> - script requires a new transaction
<%@ TRANSACTION=Supported%> - script not as a transaction
<%@ TRANSACTION=Not_Supported%> - script not as a transaction
INCLUDES:
#config - configures format for error messages, dates, file sizes
#echo - insert a variable into the page
#exec - insert results of an application or command line shell
#flastmod - insert last modified date/time
#fsize - insert file size
#include - include the contents of another file into the current one
<!-- #include virtual = "virtual/path/file.htm" -->
<!-- #include file = "c:/path/file.htm" -->
ADODB
set myobject = Server.CreateObject()
ADODB.Command
ADODB.Connection
Dim db
set db = Server.CreateObject("ADODB.Connection")
db.Open "ODBCConnectionName", "username", "password"
Set conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0; " _
& "Data Source=C:\Inetpub\wwwroot\testdatabase.mdb; " _
& "Persist Security Info=False"
conn.Open
ADODB.Error
ADODB.Field
ADODB.Parameter
ADODB.Property
ADODB.Record
ADODB.Recordset
ADODB.Stream
Command Object - Use this object to invoke a stored procedure.
PROPERTIES:
ActiveConnection - name of the connection object
CommandText - string containing command you wish to execute (SQL)
CommandaType - type of command that is executed
Name - string representing the name of the command object
Prepared - Boolean value True = underlying data provider is instructed to store a version of the command before executing
State - integer value indicating whether Command Object is open or not.
COLLECTIONS:
Parameter
METHODS:
Cancel - cancel execution
CreateParameter - create a new parameter Ex: Set myParam = somecommandname.CreateParameter([Name], [Type], [Direction], [Size], [Value])
Execute - execute the command
Connection Object PROPERTIES
Attributes
read/write - property to set whether the connection object performs retaining commits or retaining aborts
CommandTimeout - numb of seconds the connection should wait for a result of an execute method. Default is 30 seconds
ConnectionString - string containing the definition of the Provider, Data Source, User ID, Password, File Name, Remote Provider and remote server
ConnectionTimeout - Number of seconds to wait while attempting to make a connection, default is 15 sec
CursorLocation - Indicates where the cursor for the current connection should be created
DefaultDatabase - if no database is stated in the connection string, this database will be used.
IsolationLevel - determines what happens to the underlying records when a transaction is committed or aborted
Mode - Level of permissions for the connection
Provider - name of the data provider like OLE DB
State - Integer value representing whether the connection is open (adStateOpen) or closed (adStateClosed)
Version - current version of ADO
COLLECTIONS:
Errors
METHODS:
BeginTrans - begin a transaction
Cancel - cancel execution
Close - close the connection
CommitTrans - commit the transaction
Execute - execute a query
Open - open a connection
OpenSchema - obtain information on the database structure
RollBackTrans - abort transaction before the commit
EVENTS:
BeginTransComplete - fired when BeginTrans method is called
CommitTransComplete - fired when CommitTrans method is complete
ConnectComplete - fired when connection is instantiated
Disconnect - fired when connection is set to nothing
ExecuteComplete - fired after a call to the Execute method
InfoMessage - event is a notice that the data provider has raised additional info
RollbackTransComplete - fired when a RollbackTrans is complete
WillConnect - fired before connection is established but connection object is instantiated
WillExecute - fired before the successful execution of a command
PROPERTIES:
Description - string of the error
HelpContextID - the error has an accompanying Windows Help file
HelpFile - string of the path of the help file
NativeError - long value of error number raised by the native data provider
Number - long error number. no error = 0
Source - sting represents the name of the object that caused the error
SQLState - 5 character error code returned when error on processing a SQL
FIELD OBJECT
PROPERTIES:
ActualSize - long number of the number of characters contained by the field
Attributes - retrieve the attributes of the field read only
DefinedSize - use definedsize to determine if what you are passing into a field is larger than the record
Name - field's name from the database read only
NumericScale - number of decimal places to which numeric data will be rounded
OriginalValue - value of the field before any changes are made
Precision - number of digits numeric values will be resolved
Status - indicates if a field object has been added. resets on
Update method
UnderlyingValue - Read only of current value of the current field
Value - value assigned to the field object
METHODS:
AppendChunk - appends a large amount of text or binary to a field object
GetChunck - retrieves a large amount of text or binary from a field object
Parameter Object
PROPERTIES:
Attributes - retrieve the attributes read only
Direction - input, output, or both
Name - name of parameter
NumericScale - number of decimal places to which numeric data will be rounded
Precision - number of digits numeric values will be resolved
Size - long number of max bytes or characters for the param
Type - integer value representing the data type of the parameter
value - value of the parameter
Property Object
PROPERTIES:
Attributes - retrieve the attributes read only
Name - name of property
type - integer value representing the data type of the parameter
value - value of the property
Record Object PROPERTIES
ActiveConnection - indicated the connection object
Mode - shows available permissions for modifying data
ParentURL - read only indicates URL of the parent record
RecordType - read only type of record, single, structured, collection
Source - what the current record represents, URL, reference, or recordset
State - either open or closed. If open also indicates state of executing record
COLLECTIONS:
Fields
METHODS:
Cancel - cancel execution
Close - Close the open record
CopyRecord - copy the current record
vVariable - myrecord.CopyRecord([Source], [Destination], [Username], [Password], [Options], [Async])
DeleteRecord - delete the record object
GetChildren - returns all the files and folders of the record object
MoveRecord - move the record object from one location to another
Open - open an existing, or create a new file
Recordset Object
PROPERTIES:
AbsolutePage - a recordset is separated into pages by the ADO. This is the number of pages in long
AbsolutePosition - ordinal number of the current record in the recordset
ActiveCommand - Name of the command object that created the recordset
BOF - Boolean file indicating whether the recordset is at the beginning of file.
Bookmark - retrieve a unique id number of the current record
CacheSize - number of records cached. Must be greater than 1. Forcing more than 1 could cause memory hogs.
CursorLocation - adUseClient or adUseServer determines client-side or server-side creation of the recordset.
CursorType - default adOpenFowardOnly. If open it's read only. If closed read/write
DataMember - Name of data member to obtain from the datasource property.
DataSource - specify an object containing data.
EditMode - current editing state, in progress, not saved, added
EOF - Boolean file indicating whether the recordset is at the end of file.
Filter - filter out records
Index - name of index being used by the recordset
LockType - editing settings, Read-Only, Pessimistic, Optimistic, or BatchOptimistic
MarshalOptions - packaging and sending groups of records from client to server. Either modified only or all.
MaxRecords - set the max number of records. default is 0 which is no max
PageCount - if not supported or undetermined = -1
RecordCount - exact number of records returned. if not supported or undetermined = -1
Sort - specify the name of a field to be sorted by
Source - SQL string, stored procedure, or name of command
State - adStateOpen or adStateClosed if record is open or closed
Status - batch update or bulk manipulation
StayInSync - Boolean indicating whether parent should change if child changes
COLLECTIONS:
Field
Property
METHODS:
AddNew - add a new record
Cancel - cancel operation
CancelBatch - cancel all pending updates
CancelUpdate - cancel updates to current record
Clone - duplicate the recordset
Close - close the recordset
CompareBookmarks - determine if two bookmarks are equal
Delete - delete current record or group of records from recordset
Find - search recordset Ex: myrecordset.Find(Criteria, [SkipRows], [SearchDirection], [Start])
GetRows - set recordset into an array Ex: myrecordset.GetRows([Rows],[Start],[Fields])
GetString - recordset as string Ex: myrecordset.GetString(StringFormat, [NumRows],[ColumnDelimiter],[NullExpr])
Move - move the current record pointer either forward or backward Ex: myrecordset.Move(NumRecords,[Start])
MoveFirst
MoveLast
MoveNext - very important when in a loop to avoid infinite looping
MovePrevious
NextRecordset - move to another recordset
Open - myrecordset.open [Source], [ActiveConnection], [CursorType], [LockType], [Options]
Requery - repopulate the current recordset
Resync - refresh the data
Save - save the current recordset
Seek - locate in the current index a value
Supports - determine if the data vendor supports a certain function
Update - save changes into the database
UpdateBatch - save all changes into the database
Stream Object
PROPERTIES:
Charset - identify character set
EOS - Boolean determining End Of Stream
LineSeparator - indicate the character indicating the end of a line. Default is a carriage return + line feed (vbCrLf)
Mode - permissions in the connection object
Position - current byte or character position
Size - length in bytes of stream
State - open or closed
Type - either data (byte) or character (text) based
METHODS:
Cancel - cancel the execution of the stream
Close - close the stream
CopyTo - copy into another stream
Flush - empty all contents of the stream
LoadFromFile - load a stream into a file
Open - open or create a stream
Read - read a specific number of bytes
ReadText - read a specific number of characters
SaveToFile - save the current stream to a file - mystream.SaveToFile(Filename, [Options])
SetEOS - Set the current byte or character position as the end of stream
SkipLine - skip a line when reading characters from a text stream
Write - write byte date to stream
WriteText - write character date to stream
Dictionary - Acts like a two dimensional array.
PROPERTIES:
CompareMode - VBS only. string comparison mode for keys.
Count - Read only of the number of key/item pairs inthe Dictionary.
COLLECTIONS:
Count
Item
Key
METHODS
Add(key, item)
Exists(key) - boolean value
Items() - Returns an array.
Keys() - Returns an array.
Remove(key)
RemoveAll()
IIS - Default IIS settings for a web site is Read Only.
Threading
Single - Old, used back with Win 3.x
Multi
Neutral
- The best method.
- Eaisest to scale