Server. Transfer and response. Redirect

Source: Internet
Author: User

Response. Redirect simply sends a message to the browser, telling the browser to locate another page. You can use the following Code Set  
The user directs to another page:  
Response. Redirect ("webform2.aspx ")  
Or  
Response. Redirect ("http://www.cnnas.com /")  
Server. Transfer also uses one statement to direct the user to another page, for example, server. Transfer ("webform2.aspx ").  
However, this statement has a series of unique advantages and disadvantages.  
First, you can use server. Transfer to direct to another page to reserve server resources. Instead, you can change the server's "Focus" and transfer requests. 
Tell the browser to redirect, which means that you will not occupy a large number of HTTP requests, so this can reduce the pressure on the server and make your server  
It runs faster.  
However, please note that because "transfer" can only run between the same site on the same server end, you cannot use  
Server. Transfer redirects the user to the site on another server. To redirect to a site other than the server, only  
Response. Redirect can do this.  
Second, server. transfer retains the URL address of the browser. This is helpful for streamlined data input, but it also adds debugging  
Complexity.  
Also, the server. transfer method has another parameter -- "preserveform ". If you set this parameter to true, for example: 
Server. Transfer ("webform2.aspx", true), the query string and any form variable will be passed to your location at the same time.  
.  
For example, webform1.aspx has a text box named textbox1, which is passed to webform2.aspx using preserveform to true,  
You can still use request. Form ("textbox1") to obtain the value of the text box.  
This technology is useful for wizard-type multi-page input, but here you must note that when you use the preserveform parameter,  
ASP. NET has a bug. Normally, an error occurs when attempting to pass the form or query string value. See:  
Http://support.microsoft.com/default.aspx? Id = KB; en-US; q2017920 
The unofficial solution is to set the enableviewstatemac attribute to true on the target page you want to pass, and then set it back  
False. This indicates that you need to use the false value of enableviewstatemac to solve this problem.  
Conclusion: Response. Redirect simply tells the browser to access another page. Server. Transfer helps reduce server requests and maintain  
The URL in the address bar remains unchanged, allowing you to pass the query string and form variables to another page (a small defect ).  
Important: Do not confuse server. Transfer and server. Execute, server. Execute to execute a page and return the result  
As a result, server. Execute is useful in the past, but in ASP. NET, it is replaced by the fresher method, so ignore  
Server. Execute 

 

Other:

1. browser ASP file request-> server execution-> response. Redirect statement-> the server sends the address following response. Redirect to the client browser-> the browser requests a new address.

2. browser ASP file request-> server execution-> server. Transfer statements-> server redirection to new files

Switch object:

1. response. Redirect can switch to any existing webpage.

2. server. Transfer can only switch to a webpage in the same directory or subdirectory.

Data Confidentiality:

1. After response. Redirect, The address will change to the page address after the jump.

2. The address remains unchanged after server. Transfer, hiding the address of the new web page and the parameter values attached to the address. Data Confidentiality.

Transmitted data volume (parameters attached to the URL ):

1. The data that response. Redirect can transmit is limited to 2 kb.

2. When the transmitted data exceeds 2 kb, you must use server. Transfer.

 


 

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.