Comparison of four page Jump technologies in ASP. NET web pages

Source: Internet
Author: User
Tags rounds

1. Three Jump Modes

1,Response. Redirect:The method used to jump to the page is not fast, because it requires two rounds (two PostBack), but he can jump to any page, there is no website page restriction (that is, you can jump from Yahoo to Sina), and you cannot skip logon protection. However, slow speed is the biggest defect!
Redirect jump mechanism: First, 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. It should be noted that after the jump, all data information stored in the internal space will be lost, so session is required.

By the way, how to use the Redirect method to use Chinese Characters in query strings is often garbled because URLs do not support Chinese characters. In this case, the conversion is required:
String message = server. urlencode ("welcome to the blog ");
Convert the query string first:
Response. Redirect ("webform2.aspx? MSG = "+ message );

 

2,Server. Transfer: Fast, only one PostBack is required, ...... It must be on the same site because it is a server method. In addition, he can skip logon protection.
You can write a smallProgramTry: design a jump from page 1 to page 2, but login and form authentication are required to enter page 2. However, if the jump statement uses transfer, the logon page will not pop up. The redirection request of this method occurs on the server, so the URL address of the browser still retains the address of the original page!

3,Sever.exe cute:This method is mainly used in the page design, and it must jump to the page under the same site. This method needs to be used to insert the output results of a page to another ASPX page. Most of them are in the table, where a page is nested to another page.

 

2. There are four page navigation methods in Asp.net. How do I select one for your page?

◆ 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 userHyperlinkWidgetTo dynamically set the navigateurl attribute.

◆ If you wantConnect to another serverResources, useResponse. 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 execute the processTransfer to the sameWebAnother ServerAspxPage, Should be usedServer. TransferInstead of response. Redirect, because server. Transfer can avoid unnecessary network communication to achieve better performance and browsing effect.

◆ If you want to capture the output result of An ASPX page and insert the result to a specific location of another ASPX page, useServer. Execute.

Note: If you want to ensure that the HTML output is valid, use response. Redirect instead of server. Transfer or server. Execute.

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

 

Appendix: Asp.net comparison of methods for redirecting from one page to another

There are many ways to achieve page Jump, except that the server control is encapsulated by Asp.net, other methods are available in ASP.

In so many implementation methods, the same function is implemented. Why do we need to support so many methods? Which method should we choose in actual application? Maybe most of us need to jump and use it whenever we think about it. We never think about them differently. In fact, I did the same before, understanding that they do not have a system cannot give full play to their respective advantages. Okay. Now let's take a look at their respective purposes.

1. hyperlink

This is not to mention, the simplest.

2. Server Control hyperlink

Use the navigateurl attribute to specify the URL to jump. It is mainly used by the user to determine when to convert pages, but the program is used to control the conversion target.

3. Program Control

① Response. Redirect ()
Server -------- notify client ---------- request jump to server
It is mainly used to pass the query string as part of the URL to another page, or the page to jump to is an HTML page

② Server. Transfer ()
The biggest feature of this method is that the URL is still the URL of the page before the jump.
It is mainly used to transfer the execution process to another ASPX page of the same web server. Because it retains the request and session values after the jump, and can use the data on the page before the jump.

③ Server. Execute ()
After this method is executed, the program control will return to the jumpCodeThe Next Generation Code of is equivalent to our modal window. In this case, you can get the return value of the page that has been redirected.
It is often used to assist in selection, and then return the selected value to the current page.

1. Three Jump Modes

1,Response. Redirect:The method used to jump to the page is not fast, because it requires two rounds (two PostBack), but he can jump to any page, there is no website page restriction (that is, you can jump from Yahoo to Sina), and you cannot skip logon protection. However, slow speed is the biggest defect!
Redirect jump mechanism: First, 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. It should be noted that after the jump, all data information stored in the internal space will be lost, so session is required.

By the way, how to use the Redirect method to use Chinese Characters in query strings is often garbled because URLs do not support Chinese characters. In this case, the conversion is required:
String message = server. urlencode ("welcome to the blog ");
Convert the query string first:
Response. Redirect ("webform2.aspx? MSG = "+ message );

 

2,Server. Transfer: Fast, only one PostBack is required, ...... It must be on the same site because it is a server method. In addition, he can skip logon protection.
You can try to write a small program: design a jump from page 1 to page 2, but to enter page 2, You need to log on and perform form authentication. However, if the jump statement uses transfer, the logon page will not pop up. The redirection request of this method occurs on the server, so the URL address of the browser still retains the address of the original page!

3,Sever.exe cute:This method is mainly used in the page design, and it must jump to the page under the same site. This method needs to be used to insert the output results of a page to another ASPX page. Most of them are in the table, where a page is nested to another page.

 

2. There are four page navigation methods in Asp.net. How do I select one for your page?

◆ 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 userHyperlinkWidgetTo dynamically set the navigateurl attribute.

◆ If you wantConnect to another serverResources, useResponse. 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 execute the processTransfer to the sameWebAnother ServerAspxPage, Should be usedServer. TransferInstead of response. Redirect, because server. Transfer can avoid unnecessary network communication to achieve better performance and browsing effect.

◆ If you want to capture the output result of An ASPX page and insert the result to a specific location of another ASPX page, useServer. Execute.

Note: If you want to ensure that the HTML output is valid, use response. Redirect instead of server. Transfer or server. Execute.

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

 

Appendix: Asp.net comparison of methods for redirecting from one page to another

There are many ways to achieve page Jump, except that the server control is encapsulated by Asp.net, other methods are available in ASP.

In so many implementation methods, the same function is implemented. Why do we need to support so many methods? Which method should we choose in actual application? Maybe most of us need to jump and use it whenever we think about it. We never think about them differently. In fact, I did the same before, understanding that they do not have a system cannot give full play to their respective advantages. Okay. Now let's take a look at their respective purposes.

1. hyperlink

This is not to mention, the simplest.

2. Server Control hyperlink

Use the navigateurl attribute to specify the URL to jump. It is mainly used by the user to determine when to convert pages, but the program is used to control the conversion target.

3. Program Control

① Response. Redirect ()
Server -------- notify client ---------- request jump to server
It is mainly used to pass the query string as part of the URL to another page, or the page to jump to is an HTML page

② Server. Transfer ()
The biggest feature of this method is that the URL is still the URL of the page before the jump.
It is mainly used to transfer the execution process to another ASPX page of the same web server. Because it retains the request and session values after the jump, and can use the data on the page before the jump.

③ Server. Execute ()
After this method is executed, the program control will return the next generation code of the jump code, which is equivalent to our modal window. At this time, the return value of the jump page can be obtained.
It is often used to assist in selection, and then return the selected value to the current page.

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.