ASP redirection-response. Redirect and server. Transfer/server.exe cute

Source: Internet
Author: User
Document directory
  • Syntax
  • Example

Summary:
Response. Redirect: client action
Server. Transfer: Server action. ie cannot perceive the redirection and can pass the current page environment.
Server.exe cute: Server action. ie cannot perceive the redirection. It can pass the current page environment and return to the original page after execution, which is similar to calling an external function.
Execute can directly execute code and pass the current page Environment

ASP redirection-response. Redirect and server. Transfer
-Response. Redirect and server. transfer2006-4-6 23:37:34 www.aspxuexi.com

1. Client redirection Problems
ASP programmers usually use the response. Redirect statement to load a page to the webpage currently being executed. However, many people do not realize that this statement will not automatically load and execute new web pages on the server immediately. What is actually done is to add an HTTP redirection header to the output stream sent to the customer by the Web server. This header is as follows:
HTTP/1.1 302 Object Moved
Location Newpage. asp
The standard HTTP status information "302 Object Moved" in this header informs the browser that the requested resource has been moved. The Location header provides the corresponding webpage address. Of course, this address is not necessarily true. What we are doing now is to "cheat" the browser so that the browser can find the desired webpage in another location. What actually happens is that the server executes the requested webpage, but notifies the browser that the webpage required has been moved. This is why the Redirect method must be executed before any page content is sent to the browser.
When a browser receives the "302 Object Moved" message, it interrupts the current request and sends a new request to the webpage specified in the location value. This works the same way as when a meta HTTP-EQUIV tag is used in the <Meta HTTP-EQUIV = "refresh" content = "0; url = Newpage. asp">
Therefore, redirection actually occurs on the client, not on the server. If a proxy server is in use on the connected client, a false message may be displayed. This is how to use response. the reason why the message "the object you requested has been moved and can be found here" is often displayed on the client during redirect. Correct buffering can usually prevent this problem.
When using response. Redirect in IIS 4.0 or earlier versions, you should enable the buffer at the beginning of the ASP Web page, and then call response. Clear before executing the response. Redirect method. Of course, in ASP 3.0, webpage buffering is enabled by default, so this is not a problem. As long as response. Clear is used before the statement is executed, the previous output will not be sent to the customer.

2. Server redirection in ASP 3.0
In ASP 3.0 and IIS 5.0, two new Server Object methods are used in almost all cases.Execute and transfer can avoid client redirection. These two methods enable the control to immediately go to another Web PageThe webpage can be an ASP Webpage or any other resource, such as an HTTP webpage, compressed file, or other types of files.
The difference between them is:Execute Method"Call" another web page, similar to calling a sub-program or function in script code. When another Web page or resource has been executed or transferred to the client, control the next statement returned to the statement that calls the execute method on the original web page, and continue to execute. And useTransfer MethodThe control is no longer returned to the original page. The execution stops at the end of the webpage or resource to be transferred.
  The current webpage environment is also sent to the target webpage or resource, so these two methods are more useful.The webpage environment contains the values of all the variables in the original ASP object, such as the set of request, response, and session objects and all their attributes. Even if the webpage is not in the same virtual application, the environment of the Application object is also transmitted.
The result is that the browser thinks it is still receiving the original page, and does not know what the server is doing. The address bar of the browser always displays the same URL, and the back, forward, and refresh buttons work normally. This is usually not the case when client redirection is used, especially when HTML meta elements are used. ASP redirection

==================================

The execute method executes an ASP file from inside another ASP file. After executing the called. asp file, the control is returned to the original. asp file.
The excute method can execute another ASP file in an ASP file. After the. asp file is called outside the execution, the control returns the original. asp file.

Syntax
Server.Execute(path) 

Parameter Description
Path Required. The location of the ASP file to execute
Required. Location of the ASP file to be executed
Example

File1.asp:

<%response.write('I am in File 1!<br />')Server.Execute('file2.asp')response.write('I am back in File 1!')%>

File2.asp:

<%response.write('I am in File 2!<br />')%>

Output:

I am in File 1!I am in File 2!I am back in File 1!

Also look at the server. Transfer Method to see the difference between the server. Execute and server. transfer methods.
Observe what is the difference between the server. Transfer Method and server. Execute method.

================================

Execute's clever use

Execute is a new function of vbscript5.0. The following is an example:
If we have a form that contains a large number of input, radio, select, and other user inputs, the common methods for processing files in ASP are:
Dim company, name, email, tel, fax, Web 'may have a lot more ....
Company = request. Form ("company ")
.....
Web = request. Form ("Web ")
Then, store the database or perform other operations.
It is very troublesome to use form declaration and value for each form variable. Is there a better way? We know:
For each item in request. Form
Response. Write item & "=" & request. Form (item) & "<br>"
Next
The values of all forms can be displayed, but they cannot generate multiple variables and obtain the corresponding values. Example: Company = request. Form ("company ")
What should we do? Execute:
For each item in request. Form
'Response. Write item & "=" & request. Form (item) & "<br>"
'Note the following sentence:
Execute item & "=" "& request. Form (item )&""""
Next
The above execute "=" is followed by two double quotes ("), and then four ("), in order to convert them into strings for execute, otherwise, unexpected errors may occur!
Now, you can reference the corresponding values for receiving data or other processing.
Example: response. Write Company & "<br>"

 

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.