Differences between Asp.net response. Redirect and server. Transfer (execute)

Source: Internet
Author: User

Reprinted:

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 switches to a new file switch object:

The server. transfer method has another significant advantage over the Redirect method. The content in the request set is not lost during page conversion, which makes programming very convenient.
Generally, use the server. Transfer Method as much as possible (the premise is that the server is IIS). The server. Transfer Method is faster and can be compatible with any browser because it is only executed on the server.

 

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

1. server. Transfer can only switch to a webpage in the same directory or subdirectory. 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. Amount of data transferred (parameters attached to the URL ):

 

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

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

 

Response. RedirectMethod causes the browser to link to a specified URL. When the response. Redirect () method is called, it creates a response, and the response header indicates the status.Code302 (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. when the Redirect method is used, the reset to operation occurs on the client, involving two communications (two back and forth) with the server in total: the first request to the original page gets a 302 response, the second is the new page stated in the request 302 response. The page after the reset is obtained.Server. TransferMethod to transfer 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 reset 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.

 

Speaking of server. Transfer, You Have To Say server. Execute. The main difference is that after server. Execute finishes execution on the second page, it will return the first page for further processing.

Server.transferand server.exe cute also have limitations. They can only redirect to the same web application page, and this process is transparent to the client.

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.