1. response. Redirect ():
The response. Redirect method causes the browser to link to a specified URL. When the response. Redirect () method is called, it creates a response. The response header indicates the status code 302 (indicating that the target has changed) and the new target URL. The browser receives the response from the server and sends a request to the new URL using the information in the response header.
This means that response is used. in the Redirect method, the redirection operation occurs on the client, involving two communications with the server (two back and forth) in total: the first request to the original page, and a 302 response is obtained, the second is the new page stated in the 302 response to the request, and the page after the redirection is obtained.
2. server. Transfer ():
Server. transfer is a new feature in IIS 5.0. It solves
Two important defects of response. Redirect:
1) In response. Redirect, we cannot get any output on the first page.
2) response. Redirect will lose all attributes in the request
Of course, we can solve this problem through some other methods, such as session. However, some page parameters are transmitted in the request. In this case, it won't work.
3) response. Redirect requires the client to initiate another request.
Server. Transfer solves these problems. It initiates a request directly from the server to the next page and does not require the client to send the request again.
If your webpage is very dependent on response. Redirect, this small change can increase the efficiency by nearly 25%. (According to Microsoft documentation ).
The server. Transfer Method transfers the execution process from the current aspx file to another ASPX page on the same server. When server. Transfer is called, the current ASPX page is terminated and the execution process is transferred to another ASPX page. However, the new ASPX page still uses the response stream created on the previous ASPX page.
If you use the server. transfer method to implement navigation between pages, the URL in the browser will not change because the redirection is completely performed on the server side, and the browser does not know that the server has executed a page transformation.
By default, server. the transfer method does not pass form data or query strings from one page to another, but you only need to set the second parameter of this method to true, the form data and query string of the first page can be retained.
At the same time, use server. note that the target page will use the response stream created on the original page, which leads to ASP.. Net machine authentication check (MAC), The viewstate of the new page is deemed to have been tampered. Therefore, to retain the form data and query string set of the original page, you must set the enableviewstatemac attribute of the target page command to false.
Server. one disadvantage of transfer () is that when the user is in. aspx submits a form, and then uses server. transfer () enters B. aspx. If you refresh the page, the browser will ask you if you want to "retry" the form. If you click "yes", the data in the form will be resent to the server. For example, the function of sending a form is to insert a record into the database, and the result is not expected to happen-the same form is added to the database multiple times.
3. server. Execute
Server. the execute method allows the current ASPX page to execute a specified ASPX page on the same web server. When the specified ASPX page is executed, the control process returns to the original page to issue the server. the location of the execute call.
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.
Server. Execute ("another. aspx") and server. Transfer ("another. aspx") are different:
Execute transfers the execution from the current page to the specified page and returns the execution to the current page.
Transfer completely transfers the execution to the specified page
Summary:
When the network status is good, the Redirect (URL) method is the most efficient !! Can be redirected to aspx or non-aspx (HTML) resources on the same or non-Same server
The server. Transfer Method and server. Execute method are the most flexible !! But it can only be transferred to the same application directory, which may lead to unexpected results.
The server. Execute method occupies the most resources.