In ASP. NET, there are three methods for server-side redirection.
1. server. Transfer ("Newpage. aspx "):
The server stops parsing this page, saves the data on this page before turning, redirects the page to Newpage. aspx, and returns the result of adding the Newpage. ASPX page to the browser.
2. server. Execute ("Newpage. aspx ");
After the server saves this page to the previous data, It redirects the page to Newpage. aspx for execution, returns this page for execution, merges the three results, and returns them to the browser.
3. response. Redirect ("Newpage. aspx "):
When the server executes this method, it sends a message to the client browser, asking the client browser to send a new HTTP request. The request URL is "Newpage. aspx ". The browser then forwards the HTTP request to the Newpage. ASPX page.
Summary:
Both 1 and 2 are server-side page redirection, so the target page can access the query string set and form variable set on the Source Page, there is no page change record in the browser (that is, the URL displayed in the browser will not change), So if you refresh this page, there may be some other unexpected situations.
3. Excessive network latency occurs because the server must first notify the client and then send an HTTP request.
How to Select page redirection Method
· Use a hyperlink if you want to determine the target and time of the jump.
· To decide the jump target by a program and decide the jump time, use the web server's hyperlink control to dynamically set its navigateurl attribute.
· When the query string needs to be retained to the server as part of the URL, because the other two methods cannot achieve two PostBack operations, the data is first brought back to the server, so response. Redirect is used.
· If you want to capture the output result of An ASPX page and insert the result to a specific location of another ASPX page, use server. Execute.
· If you want to ensure that the HTML output is valid, use response. Redirect instead of server. Transfer or server. Execute. The reason is as follows.
About server. Execute
This page navigation method is similar to calling the callback function for the ASPX page. The called page can access the form data and query string set of the calling page, therefore, set the enableviewstatemac attribute of the called page command to false.
By default, the output of the called page is appended to the current response stream. However, server. the execute method has an overloaded method that allows a textwriter object (or its sub-object, such as the stringwriter object) to obtain the output of the called page, rather than directly appending it to the output stream, on the original page, you can easily adjust the location of the output result of the called page.
By the way
Because URLs do not support Chinese characters, garbled characters are often used for query characters.
Therefore, when we append a query string to a URL to be redirected on the server, we can encode the string and decode it when receiving the query string on the target page.
String message = server. urlencode ("welcome ");
Response. Redirect ("webform2.aspx? MSG = "+ message );
Reference: Http://www.jb51.net/article/16835.htm
Supplement:
When cross-page transfer (postbackurl setting) or server is used. the transfer method. When the source webpage and the target webpage are in the same web application, the previouspage attribute of the target webpage has reference to the source webpage (in other cases, the previouspage attribute is null ), this previouspage can be used in two ways.
I. Non-strongly typed:
In this case, we use page. previouspage obtains a reference of the page type. Therefore, you cannot directly access the common attributes of the source webpage. You can only call its findcontrol method to find the required control and indirectly obtain the property value of the control.
Ii. Strongly typed source web pages:
Add a <% @ previouspagetype virtualpath = "~ /Sourcepage. aspx "%> in this way, the page. previouspage attribute of the target webpage is automatically forced into the source webpage class. You can also add a <% @ reference page = "~ /Sourcepage. aspx "%>. In this way, the sourcepage will become an available class in the program. Therefore, you only need to forcibly convert page. previouspage to the sourcepage type to obtain the public attribute of the source webpage.
However, cross-webpage transmission sends a new http post request to the target webpage instead of an http get request (the ispostback attribute of the target webpage is false). server. the transfer method is performed on the server. To determine which method is used for this redirection on the target webpage, you can check the iscrosspagepostback attribute of the previouspage attribute of the target webpage. If this attribute returns true, cross-page transmission is used. If the return value is false, the system uses the server. Transfer Method for transmission.
Supplement
Today I wrote a "response. reirect () method depth analysis", here: http://www.cnblogs.com/ybwang/archive/2010/07/20/1781800.html