YouTip LogoYouTip

Asp Quickref

* * * ASP Quick Reference from . Print it out and put in your pocket for quick access. * * * ## Basic Syntax ASP scripts are surrounded by . Writing output to the browser: The default language in ASP is VBScript. To use other scripting languages, insert a language declaration at the top of the ASP page: ## Forms and User Input Request.QueryString is used to collect values from forms with method="get". Information transmitted from the form using the GET method is visible to all users (appears in the browser's address bar), and there is a limit on the amount of information that can be sent. Request.Form is used to collect values from forms with method="post". Information transmitted from the form using the POST method is invisible to users, and there is no limit on the amount of information that can be sent. ## ASP Cookies Cookies are commonly used to identify users. A cookie is a small file that the server leaves on the user's computer. Each time the same computer requests a page through a browser, it will send the cookie. The Response.Cookies command is used to create cookies: **Note:** The Response.Cookies command must appear before the tag! The "Request.Cookies" command is used to retrieve cookie values: ## Including Files By using the #include directive, you can insert the content of another ASP file into an ASP file before the server executes it. The #include directive is used to create functions, headers, footers, or elements that need to be reused across multiple pages. Syntax: or Use the keyword virtual to indicate a path that starts from a virtual directory. If a file named "header.inc" is located in the virtual directory /html, the following line will insert the content of the "header.inc" file: Use the keyword file to indicate a relative path. A relative path starts from the directory that contains the referenced file. If you have a file in the html directory and the "header.inc" file is in the html head, the following line will insert the "header.inc" file's content into your file: Use the keyword file with syntax (..) to reference files in higher-level directories. ## Global.asa The Global.asa file is an optional file that can contain declarations of objects, variables, and methods that are accessed by every page in the ASP application. **Note:** The Global.asa file must be placed in the root directory of the ASP application, and each application can only have one Global.asa file. The Global.asa file can only contain the following: * Application events * Session events * declarations * TypeLibrary declarations * #include directives **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 is placed in event handlers. **Note:** Since we cannot insert scripts using ASP script delimiters () in the Global.asa file, we need to place subroutines inside HTML tags: 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 ** Declarations** You can create objects with session or application scope in the Global.asa file by using the tag. **Note:** The tag should be outside the tag! Syntax: ....... **TypeLibrary Declarations** A TypeLibrary is a container that holds DLL files corresponding to COM objects. By including a call to the TypeLibrary in the Global.asa file, you can access constants of COM objects, and ASP code can also report errors better. If your Web application relies on COM objects with data types declared in a type library, you can declare the type library in Global.asa. Syntax: ## Session Object The Session object is used to store information about the user session, or change settings for the user session. Variables stored in the Session object store information for a single user, and are available to all pages in the application. **Collections** * Contents - Contains all items added to the session through script commands. * StaticObjects - Contains all objects added to the session through HTML's 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 for displaying dynamic content. * SessionID - Returns the session id * Timeout - Sets or returns the timeout period for the session. **Methods** * Abandon - Abandons all objects in the Session object. ## Application Object A group of ASP files that work together to accomplish a task is called an application. The Application object is used to tie these files together. All users share one Application object. The Application object stores information that will be used by many pages in the application (such as database connection information). **Collections** * Contents - Contains all items added to the application through script commands. * StaticObjects - Contains all objects added to the application through HTML's tag. * Contents.Remove - Removes an item from the Contents collection. * Contents.RemoveAll - Removes all items from the Contents collection. **Methods** * Lock - Prevents users from modifying the properties of the Application object. * Unlock - Allows users to modify the properties of the Application object. ## Response Object The Response object is used to send output from the server to the user. **Collections** * Cookies(name) - Sets the value of a cookie. If the cookie does not exist, it creates the cookie and sets the specified value. **Properties** * Buffer - Specifies whether to buffer the output. When output is buffered, the server prevents response to the browser until all server scripts have been processed, or until the script calls the Flush or End method. If you want to set this property, it should be before the tag in the ASP file. * CacheControl - Sets whether proxy servers can cache output generated by ASP. If set to Public, proxy servers will cache the page. * Charset(_charset_name_) - Appends the name of the character set (e.g., "ISO8859-1") to the Content-Type header in the Response object. * ContentType - Sets the HTTP content type for the Response object (e.g., "text/html", "image/gif", "image/jpeg", "text/plain"). The default is "text/html". * Expires - Sets the browser cache time in minutes before the page expires. * ExpiresAbsolute - Sets the date and time when the page cache expires 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. **Methods** * AddHeader(_name, value_) - Adds a new HTTP header and value to the HTTP response. * AppendToLog _string -_ Appends a string to the end of the server log entry. * BinaryWrite(_data_to_write_) - Writes data to the output directly without any character conversion. * Clear - Clears buffered output. Use this method to handle errors. If Response.Buffer is not set to true, this method will produce a run-time error. * End - Stops processing the script and returns the current result. * Flush - Immediately sends buffered output. If Response.Buffer is not set to true, this method will produce a run-time error. * Redirect(_url_) - Redirects the user to another URL. * Write(_data_to_write_) - Writes text to the user. ## Request Object When a browser requests a page from the server, this action is called a request. The Request object is used to get information from the user. **Collections** * 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 from 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 - Retrieves 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_) - Executes another ASP file from within an ASP file. After the called ASP file finishes executing, control returns to the original ASP file. * GetLastError() - Returns an ASPError object that describes the error 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 the transfer, control does not return to the original ASP file. * URLEncode(_string_) - Applies URL encoding rules to a string.
← Asp SummaryAsp Ajax Database β†’

YouTip © 2024-2026 | Home | Learn Technology, Build Dreams!

All content is for educational and learning purposes only.