Summary of ASP.net page redirection method

Source: Internet
Author: User
Asp.net| page

Introduction ofTransfer Execute Redirect redirection method

1.server.transfer Method:
Server.Transfer ("m2.aspx");//page turn (performed on server).
The server stops parsing this page, saves the data before it is turned on, and then shifts the page to m2.aspx,
and return the data before the turn to the browser, plus the m2.aspx page results.


2.server.execute Method:
Server.Execute ("m2.aspx");
After the server saves the data before the page is turned, the page shifts to m2.aspx execution,
Return to this page to continue. The three results are merged and returned to the browser.

All of these are server-side page turns so the browser does not appear page change records (the displayed address does not change).
Therefore, if the user refreshes this page, there may be some other unexpected situation.
This kind of page steering can accomplish some other functions, such as accessing the server-side controls on the previous page.

3.response.redirect:
When the browser requests an ASPX page, the redirect (URL) method is encountered.
The equivalent of telling the browser that you first need to access a page, so the browser to the server to send a request to this page.
Relocation is performed through the browser, resulting in additional round trips between the server and the browser.

When network conditions are not good, two requests can be significant
to reduce the application's response speed, or even to occupy extra bandwidth.

Summary:
Redirect (URL) method is the most efficient when the network is in good condition!!
Server.Transfer method and Server.Execute method are most flexible!! The
Server.Execute method consumes the most resources. &NBSP
  II,

1 Response.Redirect This jump page method jump speed is not fast, because it wants to walk 2 back (2 times postback), but he can jump to any page, no Site page restrictions (that is, can be jumped from Yahoo to Sina), and can not skip login protection. But slow speed is its biggest flaw! REDIRECT Jump mechanism: First is to send an HTTP request to the client, the notification needs to jump to a new page, and then the client sends a jump request to the server side. Note that all the data information stored in the internal space after the jump is lost, so you need to use the session.

2 Server.Transfer speed, only need one postback, but .... He must be under the same site as it is a method of the server. In addition, he can skip login protection. You can write a small program to try: Design a page to page two of the jump, but to enter the page two need to login, form certification, but if the jump statement using transfer words, it will not pop-up login page. The redirection request of this method occurs on the server side, so the URL address of the browser still retains the address of the original page!

3 Sever.execute This method is mainly used in the page design, and he must be to jump the same site under the page. This method is needed to insert the output of one page into another ASPX page, mostly in a table where one page is similar to nesting in another.

Third, how to select the page redirection method

There are four kinds of page jump navigation in asp.net, how to choose one for your page?

• Hyperlinks are most appropriate if you want to let users decide when to convert the page and which page to go to.

• If you want to use a program to control the target of a transformation, the timing of the conversion is determined by the user, using the Web server's hyperlink control to dynamically set its NavigateUrl property.

• Use Response.Redirect If you want to connect a user to a resource on another server.

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

• Need to keep the query string as part of the URL to the server, because the other 2 methods can not do 2 times postback, the data back to the server, the use of Response.Redirect.

• If you want to transfer the execution process to another ASPX page on the same Web server, You should use Server.Transfer instead of Response.Redirect, because Server.Transfer can avoid unnecessary network traffic, resulting in better performance and browsing effects.

• Use Server.Execute If you want to capture the output of an ASPX page and then insert the result into a specific location in another ASPX page.

• If you want to make sure that the HTML output is legitimate, use Response.Redirect and do not use the Server.Transfer or Server.Execute methods.

Incidentally, how to use the Redirect method to use Chinese characters in the query string, because it is often garbled, because the URL does not support Chinese characters. This time you need to convert:

String Message =server.urlencode ("Welcome to the racing column");

Convert first, use query string

Response.Redirect ("webform2.aspx?msg=" +message);

about Server.Execute

This kind of page navigation is similar to a function call to an ASPX page, where the called page has access to the form data and the collection of query strings that emit the calling page, so set the enableViewStateMac property of the page instruction for the call to False.

By default, the output of the called page is appended to the current reply stream. But The Server.Execute method has an overloaded method that allows you to get the output of the called page through a TextWriter object (or its child objects, such as the StringWriter object) instead of appending directly to the output stream, so that you can easily adjust the location of the output of the called page in the original page.




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.