Tutorials to .com

Tutorials to .com » Asp » Base » Advanced Programming ASP 3.0 (a)

Advanced Programming ASP 3.0 (a)

Print View , by: iSee ,Total views: 25 ,Word Count: 3220 ,Date: Sat, 25 Apr 2009 Time: 3:18 PM

asp 3.0 request and response handling

These two targets are provided by the ASP built-in objects in the two most commonly used. In the browser (or other user agent) and the Web server, the request and respond to the exchange of information took place through two built-in ASP objects to access and manage, the two objects as Request and Response objects.
In the ASP page to the work of almost every visit to these two objects, the use of these two objects will have an impact on the page the way the efficiency and reliability. Of course, they are mainly used for access to a user of the value back to the server, that is, from the HTML page or <FORM> were attached to the back as a URL query string, and create the appropriate output to return to the user, and they can be shared many of the same factors. For example, the use of two objects can be stored in the client computer on the cookie.
Therefore, we divided into two independent parts (part of each object), and, above all, from the client and the server that the exchange of information between the start and then an object each.
Study is:
How the client and server exchange messages or other Web resources.
Request and Response object details, as well as common ground between them.
Through a form and query string value of the corresponding visit.
How to read or create a cookie on both the client computer.
What is a server variable? How to access and modify the HTTP header.
Note the changes in other related entries, such as the use of client certificates.

Client and server exchange
To save space, the use of the content behind the "browser" (browser) the word. However, keep in mind is that Web pages can access the application must not only only browser, there are many special applications downloaded from the site pages, such as for those who are visually impaired users to design a special client program or is usually browser other difficulties. The most obvious example is the search engine used to access Web sites on the robot. Take full account of these factors, including common Web browser, the exact terms should be user agent (user agent).

Dialogue request page
When a browser to the Web site to request the page, that they must be told the server, its request for a page which. The first thing to do is establish a connection with the server name, and then the page request to provide the full path and name. Why should the entire path and name? Web is a borderless environment, it is necessary to create a logo for each client session (to be introduced in the future ASP how to do this).
This means that whenever the server send the page to the client, the server completely forget the customer. Therefore, when the customer requests a page, and a new visitors are identical. Server can not remember the customer, the corresponding, it is not possible to tell whether the last request them which page. Because the relative path can not be used to provide a page, even if the page contains links to a relative or line, such as:
<A HREF="Download.asp"> Next Page </ A>
Browser will automatically create a complete new page URL, using the current domain and path page; or use <HEAD> paragraph of page <BASE> element tells the browser to a page all links to its URL is. For example:
<BASE HERF=http://www.wrox.com/Store>
When the mouse point to a page link, the browser can see the status bar. The path of the current page and the current domain name or path-based domain name or the base of the page with the request of the combination.
1, the details of customer requests
The requested page path and name of the whole portfolio is a browser made the request when the page the only place to live server the request of the browser can also include the residence of the host browser and client operating system to run. The actual information content will be different with the browser and the corresponding changes to only a small part of the application by the other robot, such as search engines provide. Order to gain a better understanding of the information, the following is issued by IE 5.0 from a http://www.wrox.com/Store/ page
Download.asp request information:
7/8/99 10:27:16 Sent GET / store / Download.asp HTTP/1.1
Accept: application / msword, application / vnd.ms-execl, application/vnd.ms-
powerpoint, image / gif, image / x-xbitmap, image / jpeg, image / pjpeg, application/x-
comet, * / *
Accept-Language: en-us
Encoding: gzip, deflate
Referer: http://ww.wrox.com/main_menu.asp
Cookie: VisitCount = 2 & LASTDATE = 6% 2F4% 2F99 +10% 3A10% 3A13 + AM
User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98)
Host: 212.250.238.67
Connection: Keep-Alive
As can be seen, these messages have on the user agent and user to connect the details (such as default language), but also able to accept the document or the type of application a list of MIME types of these are in the back are going to see more and more. Some browsers can accept a wide range of image files and Microsoft Office file types. "Standard" file types, such as tesx / html and text / text is not included. Document list * / * that can be sent back to the browser of any type of document, from the interpretation or browser plug-ins through a (plug-in) applications to be interpreted.
cookie: the cookie contains entries stored in the client computer, and only effective in the domain. If the request is the result of clicking on the link, rather than in the browser directly into the address bar URL, the Referer: entries were displayed, it contains a link to the full page URL.
Host: entry contains the client computer's IP address or name. However, this is not enough to accurately identify the client. Because of their ISP connection through, IP addresses are dynamically assigned, or through a proxy server connection, IP address of the agent rather than the actual client.

2, the details of the server in response to information
In response to the above request, the anonymous browser (that is, users do not have to provide a user name and password access) to provide the requested page, the following is sent to the client from the server machine:
7/8/99 10:27:16 Received HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Connection: Keep-Alive
Date: Thu, 8 Jul 1999 10:27:16 GMT
Content-Type: text / html
Accept-Ranges: bytes
Content-Length: 2946
Last-Modified: Thu, 8 Jul 1999 10:27:16 GMT
Cookie: VisitCount = 3 & LASTDATE = 7% 2F8% 2F99 +10% 3A27% 3A16 + AM
<HTML>
... Rest of page ...
</ HTML>
We can see the server to the client that used their own version of the software and the first line indicates that the use of the HTTP protocol, and to return to the status code. Information "200 OK" that the request was accepted and had been met. Behind the message that the page was returned to the details, including the MIME type (Content-Length:), size (bytes), the recent changes in time, and return to storage of the client cookie. Other information in response to the page content is the information flow.
In some cases, the server in response to a request, can not go back a page, perhaps because the page does not exist, or have the customer does not have appropriate permissions to access it. We will discuss security issues at the back. Now, for the requested page does not exist (for example, a user in the browser's address bar enter the wrong URL), return to the beginning of the information as follows:
7/8/99 14:27:16 Received HTTP/1.1 404 Not Found
Server: Microsoft-IIS/5.0
...
Here, the status code and information that customers can not find the requested page. Browser can use this information to the user the appropriate information (in this case IE 5.0 does not display the response from the server information, and display the corresponding "help" in the error page), also shows the creation of the default server page ( rely on server settings).

Request and Response objects
From the asp application can respond to customer requests and server details through the ASP built-in Request and Response objects to be achieved.
Request Object: In order to provide a script when the client requests a page or send a form, the client all of the information provided. This includes browsers and can be specified in the user's HTTP variables, in this domain name stored in your browser's cookie, and any query string as a URL attached to the back page of the string or paragraph <FORM> the value of HTML control . Also provides the use of Secure Socket Layer (SSL) encryption protocol, or other authorized access, and help to connect the properties to manage.
Response object: used to access server-side concurrency by creating a response back to client information. HTTP variables for the script provided to specify the server and the server functionality and return on the contents of the browser, as well as any for this domain and stored in a new browser cookie. It also provides a series of methods used to create the output, such as the Response.Write method everywhere.
1, Request an overview of object members
a) Request a collection of objects
Request object provides a collection of five can be used to access the client requests to Web servers of all types of information, the collection of the following table:
Request a collection of objects and explain
Collection name
Description

ClientCertificate
When the client visits a page or other resources to the server to the client certificate to identify all the fields or value of the collection of entries, each member is read-only

Cookies
According to the user's request, issued by the user's system the value of all the cookie collection of the domain cookie only effective, each member of both read-only

Form
METHOD attribute values for the POST, all as a request submitted by the HTML paragraph <FORM> control the value of a collection of modules, each members are read-only

QueryString
User requests the URL attached to the back of the name / value pair or as a request and submitted for the METHOD attribute GET (or omission of its attributes), or all <FORM> the value of HTML control unit, each members are read-only

ServerVariables
Accompanying the client to issue the HTTP request header value, as well as several Web server environment variable set of values, each members are read-only


b) Request object's properties
Request object and describe the properties of only shown in the table below, which provides the user the number of bytes requested information, it is rarely used in ASP pages, we usually specify the value of attention to the request rather than the entire string.
Properties
Description

TotlBytes
Read-only to return from the client requests the number of whole bytes

c) Request object
Request object and that the only way the following table, which allows access to <FORM> paragraph from a transfer request to the server part of the integrity of user content.
Request object and description
Methods
Description

BinaryRead (count)
When the data as part of POST requests sent to the server, the request received from the client count bytes of data, returns a Variant array (or SafeArray). If the ASP code has cited the Request.Form collection, this method can not be used. At the same time, if the method used BinaryRead, Request.Form collection will not be able to visit


2, Response object members an overview of
a) Response object collection
Response object that there is only one collection, shown in the table below, the collection of settings on the client system would like to place on the cookie's value, it has a direct equivalent in the Request.Cookies collection.
Response object collection and description
Collection name
Description

Cookies
In the current response, the client returned all the cookie value, the collection was only

b) Response properties of the object
Response object provides a series of attributes, which can be read (in most cases) and modified to be able to adapt in response to the request. By the server settings, we do not need to set them. It should be noted that, when set up some attributes, use the syntax may be used usually have some differences.
Response object's properties and description
Properties
Description

Buuffer = True | False
Read / write, Boolean, indicating that an ASP page to create the output if IIS has been placed in the buffer zone until the current page of the script all the server dealt with or Flush, End method is called. In any output (including HTTP submitted information) sent to live in IIS must be set prior to this attribute. Therefore. Asp file, this setting should be in the <% @ LANGUAGE = ...%> statement after the first line. ASP 3.0 buffer for open default setting (True), and in earlier versions the default is off (False)

CacheControl "setting"
Read / write, character, setting this attribute to "Public" to allow the proxy server cache the page, such as "Private" would prohibit the occurrence of a proxy server cache

Charset = "value"
Read / write, character, in the response from the server to create for each of the HTTP Content-Type header used to attach the name of the character set (such as: ISO-LATIN-7)

Content Type = "MIME-type"
Read / write, character, specified in the HTTP response content type, the standard MIME types (for example, "text / xml" or "Image / gif"). If the default, that the use of MIME type "text / html", content type tells the browser to the desired type of content

Expires minutes
Read / write, numeric, specify a valid page in minutes the length of time, if the user request before the expiration of their effective the same page, it will directly read the contents of display buffer, after the effective period of this page will no longer remain in the private (user) or public (proxy server) in a buffer

Expires Absolute # date [time] #
Read / write, date / time type, specified when a page expired and is no longer valid when the absolute date and time

IsClientConnected
Read-only, Boolean, return customer is still connected and the status of the download page logo. In the current page has finished before the implementation, if a client transferred to another page, the logo can be used to suspend processing (using the Response.End method)

PICS ( "PICS-Label-string")
Write-only, character, create a custom page header PICS content rating terms, such as violence, sex, bad language, etc.

Status = "Code message"
Read / write, character, specify the client back to the HTTP response header that the error or the page dealing with the success of the state value and information. Such as "200 OK" and "404 Not Found"

c) Response Object
Response object provides a wide range of methods, shown in the table below, to allow direct processing to the client to return to the page content created.
Response object's methods and description
Methods
Description

AddHeader ( "name", "content")
Content through the use of name and value, to create a custom HTTP header, and increased in response. Can not replace the existing header of the same name. Once have added a header can not be deleted. This method must be the content of any page (that is, text and HTML) have been made to live before the client

AppendToLog ( "string")
When using the "W3C Extended Log File Format" document format, the user requests the Web server's log file for an additional entry. At least the requirements of the site contains pages of "Extended Properties" page, select the "URL Stem"

BinaryWrite (safeArray)
In the current HTTP output stream to write Variant types of SafeArray, without any character conversion. For information write non-string, for example, requests for custom applications or components of the binary data of the binary image file bytes, it is very useful

Clear ()
When Response.Buffer is True, the response from the IIS buffer buffer to remove the existing page content. But does not delete the HTTP response header that can be used to give up part of the completion of the page

End ()
ASP processing page so that the end of the script, and return to the current content has been created, and then give up any further processing of the page

Flush ()
Send IIS buffer pages of all the current buffer to the client. When Response.Buffer is True, you can use to send the larger part of the contents of the page to individual users

Redirect ( "url")
Response by sending a "302 Object Moved" HTTP header to instruct the browser to download according to the corresponding url address string of the page

Write ( "string")
HTTP response in the current information flow and IIS write to the specified character buffer, so that it will become part of the return of the page

In this book examples of source code, the reader will find a series of pages, demonstrate how to use the Request and Response from clients, properties, methods, and collection. From the Wrox Web site to download the Chapter02 directory, there are examples of this chapter, the rest of the page.


Asp Base Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.