There are three methods to achieve page jump through ASP:
(1)Response. Redirect
The method used to jump to the page is not fast, because it takes two rounds (two PostBack), but it can jump to any page without Site Page restrictions, logon protection cannot be skipped. 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.
(2)Server. Transfer
Fast, only one PostBack is required. However, it must be in 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! When a page is redirected, control of the page is handed over. The stored information such as request session remains unchanged during page Jump. After the jump, you can use the data submitted on the previous page.
(3)Sever. 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. That is, after the page is executed, return to the location where the original page sends server. Execute. This method allows the current page to execute another page on the same web server
So how can we use appropriate methods in a suitable situation?
· Use redirect to redirect a user to a page on another server
· Use redirect to redirect a user to a non-ASPX page
· When the query string needs to be retained to the server as part of the URL, because the other two methods cannot achieve two PostBack operations, the data is first brought back to the server using Redirect
· Transition between aspx pages (logon not involved) Using Transfer
· Execute is used to insert the output result of the ASPX page to another ASPX 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 user, use the hyperlink control of the Web server to dynamically set its navigateurl attribute.
· If you want to connect a user to resources on another server, 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.
· If you want to ensure that the HTML output is valid, use response. redirect, because server. execute or server. the transfer method returns multiple <HTML> <body> tags to the client's page, which is not a legal HTML page and may cause errors in non-ie browsers.
· Response. Redirect is used to transmit data between pages using objects such as session cookies.