ASP quick reference
ASP Quick Reference from W3CSchool. Print it out, put it in your pocket, and have it ready to use at any time.
Basic Syntax
ASP scripts are surrounded by <% and %>. Write output to the browser:
<html>
<body>
<%
response.write("Hello World!")
%>
</body>
</html>
The default language in ASP is VBScript. If you want to use another scripting language, insert a language description at the top of the ASP page:
<%@ language="javascript" %>
<html>
<body>
<%
....
%>
Forms and user input
Request.QueryString is used to collect forms with method="get" value in . Information transferred from a form using the GET method is visible to all users (appears in the browser's address bar), and there are limits on the amount of information sent.
Request.Form is used to collect values from a form using method="post". Information transferred from a form using the POST method is invisible to the user, and there is no limit on the amount of information sent.
ASP Cookies
Cookies are commonly used to identify users. A cookie is a small file that a server leaves on a user's computer. Each time the same computer requests a page through the browser, the cookie will be sent to the computer.
Response.Cookies command is used to create cookies:
<%
Response.Cookies("firstname")="Alex"
Response.Cookies("firstname") .Expires="May 10,2002"
%>
Note: The Response.Cookies command must appear before the <html> tag!
"Request.Cookies" command is used to retrieve cookie value:
<%
fname=Request.Cookies("firstname")
response.write("Firstname =" & fname)
%>
Reference file
By using the #include directive, you can insert the contents of another ASP file into this before the server executes the ASP file. ASP file. The #include directive is used to create functions, headers, footers, or other elements that need to be reused on multiple pages.
Syntax:
<!--#include virtual="somefile.inc"-->
or
<!--#include file="somefile .inc"-->
Please use the keyword virtual to indicate the path starting with the virtual directory. If a file named "header.inc" is located in the virtual directory /html, the following line of code will insert the contents of the "header.inc" file:
<!-- #include virtual =" /html/header.inc" -->
Please use the keyword file to indicate a relative path. Relative paths start with the directory containing the referenced file. If you have a file in the html directory and the "header.inc" file is at the head of the html, the following line of code will insert the contents of the "header.inc" file into your file:
<!-- #include file ="headersheader.inc" -->
Please use the keyword file with syntax (..) to refer to files in higher-level directories.
Global.asa
The Global.asa file is an optional file that contains declarations of objects, variables, and methods that are accessed by every page in an ASP application.
Note: The Global.asa file must be stored in the root directory of the ASP application, and there can only be one Global.asa file per application.
Global.asa file can only contain the following content:
Application event
Session event
<object> Declaration
TypeLibrary Declaration
include Directive
Application and Session Events
In Global.asa, you can tell the application and session objects what to do when the application/session starts and what to do when the application/session ends. The code to accomplish this task is placed in the event handler. Note: Since we cannot use ASP's script delimiters (<% and %>) to insert scripts in the Global.asa file, we need to place the subroutine in the HTML <script> tag Internal:
<script language="vbscript" runat="server">
sub Application_OnStart
' some code
end sub
sub Application_OnEnd
' some code
end sub
sub Session_OnStart
' some code
end sub
sub Session_OnEnd
' some code
end sub
</script>
<object> declaration
can be created with session or application scope in the Global.asa file by using the <object> tag Object. Note: <object> tag should be located outside the <script> tag!
Syntax:
<object runat="server" scope="scope" id="id"
{progid="progID"|classid="classID"}>
.......
</object>
TypeLibrary Declaration
A TypeLibrary is a container that holds DLL files that correspond to COM objects. By including a call to TypeLibrary in the Global.asa file, you can access the COM object's constants and your ASP code can better report errors. If your Web application relies on COM objects of data types that have been declared in a type library, you can declare the type library in Global.asa.
Syntax:
<!--METADATA TYPE="TypeLib"
file="filename"
uuid="typelibraryuuid"
version="versionnumber"
lcid="localeid"
-->
Session Object
The Session object is used to store information about the user session (session), or to change the user session (session) settings. Variables stored in the Session object store information for a single user and are available to all pages in the application.
Collection
Contents - Contains all entries appended to the session via script commands.
StaticObjects - Contains all objects appended to the session using HTML's <object> tag.
Contents.Remove(item/index) - Removes an item from the Contents collection.
Contents.RemoveAll() - Removes all items from the Contents collection.
Properties
CodePage - Specifies the character set used when displaying dynamic content.
LCID - Sets the locale identifier used to display dynamic content.
SessionID - Returns the session id
Timeout - Sets or returns the session timeout.
Methods
Abandon - Abandon all objects in the session object.
Application object
A group of ASP files that work together to complete a task is called an application. The Application object is used to bundle these files together. All users share an Application object. The Application object holds information that will be used by many pages in the application (such as database connection information).
Collection
Contents - Contains all items appended to the application via script commands.
StaticObjects - Contains all objects appended to the application using HTML's <object> tag.
Contents.Remove - Remove an item from the Contents collection.
Contents.RemoveAll - Removes all items from the Contents collection.
Methods
Lock - Prevents the user from modifying properties in the Application object.
Unlock - Allows the user to modify properties in the Application object.
Response Object
The Response object is used to send the output results from the server to the user.
Collection
Cookies(name) - Sets the value of a cookie. If the cookie does not exist, creates the cookie and sets the specified value.
Properties
Buffer - Specifies whether to buffer the output. When output is buffered, the server blocks responses to the browser until all of the server script has been processed, or until the script calls the Flush or End method. If you want to set this property, it should appear before the <html> tag in the ASP file.
CacheControl - Sets whether the proxy server can cache output produced by ASP. If set to Public, the proxy server caches the page.
Charset(charset_name) - Append the name of the character set (such as "ISO8859-1") to the Content-Type header in the Response object.
ContentType - Sets the HTTP content type of the Response object (e.g. "text/html", "image/gif", "image/jpeg", "text/plain"). The default is "text/html".
Expires - Set the browser cache time (minutes) before the page expires.
ExpiresAbsolute - Sets the date and time when the page cache will expire on the browser.
IsClientConnected - Indicates whether the client has disconnected from the server.
Pics(pics_label) - Appends a value to the PICS label of the response header.
Status - Specifies the value of the status line returned by the server.
Method
AddHeader(name, value) - Adds a new header to the HTTP response HTTP headers and values.
AppendToLog string - Append a string to the end of the server log entry.
BinaryWrite(data_to_write) - Writes data directly to the output without any character conversion.
Clear - Clear buffered output. Use this method to handle errors. If Response.Buffer is not set to true, this method will generate a run-time error.
End - Stops processing the script and returns the current results.
Flush - Send buffered output immediately. If Response.Buffer is not set to true, this method will generate a run-time error.
Redirect(url) - Redirect the user to another URL.
Write(data_to_write) - Writes text to the user.
Request object
When the browser requests a page from the server, this behavior is called a request. The Request object is used to obtain information from the user.
Collection
ClientCertificate - Contains all field values stored in the client certificate.
Cookies(name) - Contains all cookie values sent in the HTTP request.
Form(element_name) - Contains all form (input) values sent by the form using the post method.
QueryString(variable_name) - Contains all variable values in the HTTP query string.
ServerVariables(server_variable) - Contains all server variable values.
Properties
TotalBytes - Returns the total number of bytes sent by the client in the request body.
Methods
BinaryRead - Retrieve the data sent from the client to the server as part of a post request.
Server Object
The Server object is used to access properties and methods on the server.
Properties
ScriptTimeout - Sets or returns the maximum time (in seconds) that a script can run before it terminates.
Methods
CreateObject(type_of_object) - Creates an instance of an object.
Execute(path) - Execute another ASP file from within an ASP file. After the called ASP file completes execution, control returns to the original ASP file.
GetLastError() - Returns an ASPError object that describes the error status that occurred.
HTMLEncode(string) - Applies HTML encoding to a string.
MapPath(path) - Maps a relative or virtual path to a physical path.
Transfer(path) - Sends all state information to another file for processing. After transfer, program control is not returned to the original ASP file.
URLEncode(string) - Apply URL encoding rules to a string.
Source: http://www.w3cschool.cc/asp/asp-quickref.html