Differences between Server. Transfer, Server. Execute and Response. Redirect in Asp.net

Source: Internet
Author: User

Differences between Server. Transfer, Server. Execute and Response. Redirect in Asp.net

In Asp.net, page Jump is often required. Generally, Server. Transfer, Server. Execute, and Response. Redirect are used. The following describes the usage of the three methods.

(1) Server. Transfer Method:

Server. Transfer ("m2.aspx"); // page redirection (executed on the Server ).

The server stops parsing this page, saves the data on this page and then redirects the page to m2.aspx,

Add the m2.aspx page to the front data and return the result to the browser. Note that the address of the browser has not changed.

Or m1.aspx,

 

(2) Server. Execute method:

Server. Execute ("m2.aspx ");

After the server saves this page to the previous data, It redirects the page to m2.aspx for execution,

Return to this page and continue execution. Merge the three results and return them to the browser.

All of the above are server-side page redirection, so there is no page change record in the browser (the displayed address will not change ).

Therefore, if you refresh this page, there may be some other unexpected situations.

This type of page redirection can complete other functions, such as accessing the server control on the previous page.

 

(3) Response. Redirect:

When the browser requests the aspx page, it encounters the Redirect (url) method,

It is equivalent to telling the browser that you need to access a page first, so the browser then sends a request to the server to access this page.

Relocation is performed through the browser, and an additional round-trip process is generated between the server and the browser.

When the network condition is not good, the two requests will be large.

Reduces the response speed of the application, or even occupies excessive bandwidth. After the conversion, the browser address is changed and displayed as asp2.aspx.

 

Summary:

When the network status is good, the Redirect (url) method is the most efficient !!

The Server. Transfer Method and Server. Execute method are the most flexible !!

The Server. Execute method occupies the most resources.

The difference between Server. Transfer and Server. Execute is that the execution result of Execute is not returned to the current user.

· If you want users to decide when to convert a page and which page to go to, hyperlink is the most suitable.

· If you want to use a program to control the conversion target, but the conversion time is determined by the user, use the Web tracking yperLink control to dynamically set its NavigateUrl attribute.

· If you want to connect a user to resources on another server, use Response. Redirect.

· Use Response. Redirect to connect users to non-ASPX resources, such as HTML pages.

· If you want to retain the query string as part of the URL, use Response. Redirect.

· If you want to transfer the execution process to another ASPX page of the same Web Server, you should use Server. transfer instead of Response. redirect, because Server. transfer can avoid unnecessary network communication to achieve better performance and browsing performance.

· 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.

· To ensure that the HTML output is valid, use Response. Redirect instead of Server. Transfer or Server. Execute.

 

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.