ASP Seven Object Description Analysis _asp Foundation

Source: Internet
Author: User
Tags character set error code flush http request numeric value servervariables
/*-------------------ASP Document reference set-----------------------* *
*--> Author: paramecium
*--> time: 2007-4.28---2007-4.30 (originally a manual written by oneself, now sent here)
*--> Contact: caolvchong@gmail.com
*--> Document Features:
1. Review the ASP, deepen the understanding of ASP structure and the experience of ASP
2. Can be used as an ASP reference, write their own, reference to more convenient


This is the second part: ASP seven big objects
/*---------------------------ASP Seven Objects----------------------------* *
*-->application object:
Function: Share information between all users of a given application and persist during server runs
According to. Moreover, the Application object also has the means to control access to application-tier data and can be used to restart the application
Events that trigger the process when moving and stopping (OnStart event and OnEnd event)
Properties: No built-in properties
Collections: User-defined properties
Collection and description of application objects:
Contents: None of the variables stored in the Application object are defined using the <OBJECT> element (and
A collection of their values. A reference that includes a Variant array and a Variant type Object instance
StaticObjects: All variables stored in the Application object, defined with the <OBJECT> element
A collection of (and their values)
The corresponding example:
To set the Application property value:
Application ("MyVar") = "Hello"
Set application ("myobj") = Server.CreateObject ("MyComponent")
Method:
Contents.Remove (): Remove a Application collection
Contents.RemoveAll (): Remove all application collections
Lock (): Prevents other customers from modifying variables stored in the Application object to ensure that at the same time only
There is a customer who can modify and access application variables. If the user does not explicitly call unlock
method, the server will unlock the Application object after the. asp file finishes or times out
Set
Unlock (): Enables other clients to lock the application object after using the lock method, modifying the stored
The variable in the object. If this method is not explicitly called, the Web server will end or timeout in the. asp file
Post-Unlock Application Object
An example of an integrated point:
In the 1.asp:
' Set 3 Application property values
Application ("chong1") = "1th Application Collection Item"
Application ("chong2") = "2nd Application Collection Item"
Application ("chong3") = "3rd Application Collection Item"
' Set property values are kept in application.contents, the cardinality starts at 0, so you can use the
' For Loop read out
' Here's a summary of the properties of the Contents collection:
' Count property: Returns the number of items in the collection, the return value is an integer
' Item property: Used to set or return the value of a specific member in the collection, the Item property is
Contents
' The default property of the collection, so. Item (x) is equivalent to. (x)
' Key property: Key (x) returns the corresponding property name, as above
Application.contents.key (1)
' will return to Chong1
For i = 1 to Application.Contents.Count
Response.Write (Application.Contents.item (i))
Next
In the 2.asp:
' 2.asp and 1.asp share the contents of the Application object, so the collection element can be repaired
Change or delete, etc.
Application ("chong1") = "I was modified" ' Modify Application Property value
Application. Contents.Remove ("chong2") ' Delete Application Property value
For all J in application. Contents ' For each form access application
Response. Write (Application.Contents.item (j))
Next
Event: About two events onstart () and onend (), etc. summarizing Global.asa files
Experience: Normally, when you want to modify a application value, you should lock it with lock () and then modify it to fix it.
Unlock () To prevent multiple users from accessing the object concurrently after the change is completed
Common: setting, modifying and deleting application sets, combining lock and Unlock methods

*-->session object:
Function: The Session object stores the information that is required for a specific user conversation. When a user jumps between pages in an application
, variables stored in the Session object are not purged, and when the user accesses the page in the application, the
Variable always exists. When a user requests a Web page from an application, if the user does not have a session, the
The WEB server will automatically create a Session object. When a conversation expires or is discarded, the server terminates the
Session (and application difference is not shared, each user has their own sessions, which
Can be used to authenticate the user)
Collection: As with application, the session has contents and Staticobject two sets
Property:
CodePage: Read/write. Integral type. Defines the code page that is used to display the content of the page in the browser. Code
A page is a numeric value of a character set, and different languages and places may use different code pages. For example, 650001
It's utf-8,936 for GB2312.
LCID: Read/write. Int. Defines the page region identification (LCID) that is sent to the browser. The LCID is the only place to identify
An international standard abbreviation for the region, for example, 2057 defines the currency symbol for the current region as ' £ '. The LCID can also be
Used in statements such as FormatCurrency, as long as there is an optional LCID parameter. The LCID can also be
ASP processing instructions <%...%> settings, and takes precedence over the settings in the LCID attribute of the session.
SessionID: Read-only. Long integer. Returns the session identifier for this session. SessionID property returns the user's
The session identity. When you create a session, the server generates a separate identity for each session. Session label
A long shaping data type is returned. In many cases SessionID can be used for WEB page registration
Statistics
Timeout: Read/write. Integer. Defines a time-out period in minutes for this session. If the user is in the timeout week
There is no refresh or request for a Web page during the period, the session ends. Can be repaired on each page as needed
The default value is 20min, which should be shorter on a site with a high usage rate.
Method:
Abandon (): The Abandon method deletes all objects stored in the session object and releases those objects
source. If you do not explicitly call the Abandon method, the server deletes the objects once the session times out.
The following example releases session state when the server finishes processing the current page
In addition, the session, like application, has contents.remove () and
Contents.RemoveAll () method
Event: About two events onstart () and onend (), etc. summarizing Global.asa files
Common: Set, modify, delete session, in addition timeout is also commonly used, remember a bit, session relies on cookies, when the browser is closed or not
You will not be able to access the session when cookies are supported

*-->request object:
Function: The Request object retrieves the value that the client browser passes to the server during the HTTP request
Collection:
ClientCertificate: When a client accesses a page or other resource, it is used to identify the server
A set of values for all fields or entries of a client certificate, each member being a
Read the. ClientCertificate collection gets the validation field from the Web browser publishing request (by X.509
Standard designation). If the Web browser uses the Ssl3.0/pct1 protocol (that is, it uses a
https://URL, rather than http://, to connect to the server and server request authentication, the browser
The validation field will be sent. If no validation is sent, the ClientCertificate collection returns empty. Must
You must first configure the Web server to require client authentication before you can use the ClientCertificate
Collection.
Cookies: A collection of the values of all cookies issued by the user system, based on the user's request, which only
Valid for the corresponding domain, each member is read-only, cookies also have count,item,key three genera
Sex, the use of which can be likened to the application mentioned above. In addition, cookies have a property
HasKeys, indicating whether the cookie is multi-valued or single, multiple values return True, and single value returns false
Form: When the value of the property is post, all the values of the HTML control cells in the <FORM> segment that were submitted for the request
Collection, each member is read-only, and the form also has count,item,key three properties
QueryString: A name/value pair that is attached to a user-requested URL or submitted as a request and
The method property value is get (or omit its properties), and the string is represented by a question mark (?). After the value is specified, or
The value of all HTML control units in <FORM>, each member is read-only, and QueryString also has
Count,item,key Three Properties
ServerVariables: HTTP header values issued with client requests, and several Web server
The collection of values for environment variables, each member is read-only, and ServerVariables also has
Count,item,key Three Properties ServerVariables parameters I printed in the "ServerVariables
Parameter set "in the document.
Property:
TotalBytes: Specifies the total number of bytes that the client sends in the body of the request. This property allows only read
Method:
BinaryRead (): Gets the data that is passed from the client to the server as part of the POST request. This party
method to obtain data from the client and store it in SAFEARRAY. SafeArray is an array in which
Contains the dimension and boundary information, in layman's parlance, the array of the time dimension and the upper and lower bounds of the dimension are determined by the safe array
The BinaryRead method is used to read raw data that is emitted from the client as part of a POST request. This party
method is used to access data at the bottom, in contrast, the Request.Form collection is used to view the send in the advertisement request
Table data. Once the BinaryRead is invoked, any variables in the reference Request.Form collection will
Causes an error to occur. Conversely, once a variable in the Request.Form collection is referenced, the call to the
BinaryWrite will also cause errors to occur. Remember, if you are accessing a variable in the request collection without referring to the
To decide which subset the variable belongs to, search the Request.Form collection and enforce the rule.
Common: For the submission of forms or the transfer of parameters between pages, request plays an important role in distinguishing
Form and querystring two different,
When you omit these two collections with request only, the ASP will automatically adjust, but this is not good. For tables
Single, usually the request is through
Name of the form element to get the value of the form element (value)
In addition, when no component uploads files, TotalBytes is used to get the size of the uploaded file, BinaryRead ()
Used to get all the content of the uploaded form.
Of course, if you want to get the content of the file, you need to analyze and intercept the contents of BinaryRead ()

*-->response object:
Function: Send output to client, just as opposed to request
Collection:
Cookies: The value of all cookies that are sent back to the client in the current response, and this collection is write-only
Example:
' Expires set expiration event, time format # english month word number date, 4-digit year #
Response.Cookies ("name") = "Paramecium"
Response.Cookies ("name"). expires= #May 11,2007#
' As for reading, I'll use Request.Cookies.
Name=request.cookies ("name") ' So name gets "Paramecium"
' Cookies can be used as a password-free login to determine whether the user has logged in and triggered by these events, etc.
Wait
' Cookies also have count,item and key attributes
' Single cookie attribute and Dimain,haskeys,path,secure attribute, and then check

Property:
buffer=true| False: Read/write, Boolean, indicating whether the output created by an ASP page has been stored
In the IIS buffer until all server scripts for the current page have been processed or the flush, end method is
Called. This property must be set before any output, including HTTP header information, is sent to IIS. So
In an. asp file, this setting should be the first line following the <%@ language=...%> statement. ASP3.0
The default setting is buffered to On (True) and the default is off (False) in earlier versions
CacheControl: Read/write, character type, set this property to "public" allows the proxy server to cache pages,
If "Private", the proxy server cache is not allowed to occur.
Charset: Read/write, character type, enclosed in the HTTP Content-type header created by the server for each response
The name of the character set used on (for example: iso-latin-7)
Content type= "Mime-type": Read/write, character type, indicating HTTP content type of response, standard MIME
Type (for example, "Text/xml" or "image/gif"). If omitted, indicates the use of MIME types
"Text/html", the content type tells the browser what type of content is expected, about the MIME list, printed in the
MIME reference document that can be referenced when needed
Expires: Read/write, numeric, indicating the length of time the page is valid in minutes, if the user requests it to have
Before expiration of the same page, will directly read the contents of the display buffer, after this valid period, the page
The face will no longer remain in the private (user) or public (proxy server) buffer. If you want a file to stand
is terminated, the property value can be set to a very large negative number. A file is set multiple times within a
The Expires property will use the earliest time/date as the end time for the file (is a relative time)
ExpiresAbsolute: Read/write, date/time type, indicating the absolute day when a page expires and is no longer valid
Period and time. Before it expires, the cached page is displayed if the user returns to the page. If the timing is not indicated
, the home page expires at midnight on the same day. If no date is specified, the home page is specified on the day the script is run
Time expires
IsClientConnected: Read-only, Boolean, return whether the customer still connects and downloads the status flag of the page.
If a customer moves to another page before the current page has finished executing, the flag is available
To abort processing (using the Response.End method)
PICS: Write-only, character-type, create a PICS header and add it to the HTTP header in the response, PICS header
Defines the level of vocabulary in a page's content, such as violence, sex, bad language, etc.
Status: Read/write, character type, indicating that the HTTP header of the response sent back to the customer indicates that the error or page handling is
No successful status values and information. For example, "OK" and "404 Not Found"
Method:
AddHeader "name", "Content": Create a custom HTTP by using the name and content values
Header, and added to the response. The header of the existing same name cannot be replaced. Once you have added a
Headers cannot be deleted. This method must be sent to the guest in any page content (i.e. text and HTML)
Front end of the household use
AppendToLog ("string"): When using the "Extended Log file format" file format,
The log file for the Web server requested by the user adds an entry. At least the site that contains the page
Extended Properties page, select URI Stem. String is to be added to the log file
of the text. Because the fields in the IIS log are separated by commas, the string cannot contain commas
(,). The maximum length of a string is 80 characters
BinaryWrite (): Writes variant type SAFEARRAY in the current HTTP output stream without
Any character conversions. For writing information that is not string, such as a custom application request binary number
The binary byte that is or makes up the image file is very useful
Clear (): Deletes an existing buffer page from the IIS response buffer when Response.Buffer is true
Allow. But do not delete headers of HTTP responses that can be used to discard partially completed pages
End (): The ASP ends the script for processing the page and returns the currently created content, and then discards any
Further processing
Flush (): Sends all current buffered pages in the IIS buffer to the client (output in the immediate send buffer). When
When Response.Buffer is true, it can be used to send portions of a larger page to individual users.
If Response.Buffer is not set to True, this method will cause a run-time error
Redirect ("url"), by sending a "302 Object moved" HTTP header in the response, indicates
The browser downloads the corresponding address page based on the string URL, and the browser redirects to the URL.
Write ("string"): writes the specified character to the current HTTP response information flow and the IIS buffer to
To return part of the page. This value cannot include character combination%> If necessary, you can use the escape sequence%\> generation
For the. Web server when processing scripts, the escape sequence is converted and a format is lost
Out: <%=...%&gt, but this is to convert between ASP and HTML, slow down, the best way is a line
Response.Write (), Strings used & connections commonly used: cookies,buffer,content type,
Expires,status,binarywrite,clear,end,flush,redirect,write these are all very
Common and browser interaction important ingredient, cookies for the customer identity aspect, and it related to have
Expires;buffer and buffer-related clear,flush,end these are used for caching
The content type is most commonly used in the output of XML and image contents; Stutas is used to judge the state,
especially in XMLHTTP; write for output; Redirect for the transfer of content; BinaryWrite General
Used to receive uploaded file contents

*-->server object:
Features: Provides access to methods and properties on the server. Most of these methods and properties are work as utilities
Can serve the
Property:
ScriptTimeout: Integer, the default is 90 seconds, the script to set or return the page at the server exits execution and
The number of seconds that can be performed before an error is reported. When this value is reached, the page is automatically stopped from executing.
and remove from memory pages that contain errors that may go into the dead loop or those that have been waiting for others for a long time
The Web page for the resource. This prevents the server from overloading with the wrong page. For pages that run longer
Face needs to increase this value
Method:
CreateObject ("identifier"): Creates an object identified by identifier (a component, application
Or Script object, which returns a reference that can be used in code. Can be used for a virtual
The intended application (Global.asa page) creates a session-level or application-layer-wide object. The object can be
To identify with its classid, such as "{clsid:bd96c556-65a3 ... 37A9} "or a ProgID string
To identify, such as "ADODB." Connection ", usually we use ProgID
Note the following points:
1. By default, objects created by the Server.CreateObject method have page scopes. That's what
says that after the current ASP page processing completes, the server will automatically destroy these objects
2. You can destroy an object by setting the variable to Nothing or a new value
3. Cannot create an object instance with the same name as an Builtin object
Execute ("url"): Stops execution of the current page, and transfers control to the Web page specified in the URL. User's when
The former environment (that is, session state and current transaction state) is also passed to the new Web page. After the page has been executed,
Control is passed back to the original page and the statement following the Execute method continues
GetLastError (): Returns a reference to an ASP ASPError object that contains the page in ASP
Details of the most recent error that occurred during processing. The information given by the ASPError object
Contains the filename, line number, error code, and so on HTMLEncode ("string"): Returns a String that
A string is a copy of the input value string, but it removes all illegal HTML characters.
Common illegal HTML characters and their conversion characters are:
< correspondence <
> Correspondence >
& Correspondence &
corresponding
corresponding (space)
? Correspondence © (copyright)
? Corresponding ® (registered trademarks)
x corresponds to X (multiplication)
The corresponding (division)

MapPath ("url"): Returns the full physical path and file name of the file or resource specified in the URL
Transfer ("url"): Stops the execution of the current page and transfers control to the page specified in the URL. The user's current environment (i.e. session state and current transaction state) is also passed to the new page. Unlike the Execute method, when
When the new page executes, it does not return to the original page, but ends the execution process
UrlEncode ("string"): Returns a string that is a copy of the input value string, but at the URL
All characters that are not valid in the
Common illegal URL characters and their conversion characters are:
# used to flag a specific document location%23
% to encode special characters%25
& separating different values of variables to%26
+ denotes a space in the value of a variable%2b
/Represents directory path%2f
\ represents directory path%5c
= used to connect keys and values%3d
? Represents the start of a query string%3f
Space%20
. Period%2e
: Colon%3a

*-->asperror object:
Because the error mechanism IIS has been able to identify the location, temporarily skip the deep

*-->objectcontext object:
Function: Controls the transaction processing of ASP. Transaction processing is managed by Microsoft Transaction Server (MTS)
Event:
OnTransactionAbort: Fired by a discarded transaction event that occurs after the script finishes processing
OnTransactionCommit: Fired by a successful transactional event that occurs after the script finishes processing
Method:
SetAbort: Explicitly discarding a transaction
SetComplete: Overwrite any previous call to call the ObjectContext.SetAbort method
As not involved, and so on when in-depth, temporary understanding can

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.