Differences between page Jump and response. Redirect and server. Transfer

Source: Internet
Author: User

Frontend page Jump mode:
1. Jump with Frame
A window. frames. framename. Location. href = URL; // framename indicates a frame, and URL indicates the jump path.

B. Open a new window, window. Open (URL, 'framename ');
2. jump without frame
A window. Location. href = URL;
B window. History. Back (-1); // return
C window. History. Go (-1 |-2 |...); // return to the previous step | 2 |... Page
D window. navigate (URL );
E self. Location = URL;
F top. Location = URL;
G window. Location. Reload (); // refresh the current page
H parent. Location. Reload (); // refresh the parent object page
I opener. Location. Reload (); // refresh the parent window page

 

Background jump:

1. hyperlink Server Control

In HTML and ASP, we often use <a href = target. asp> Target </a> to redirect pages. this method is still available in. net, and can also be replaced by hyperlink Service controls, as shown below:

<Form ID = "form1" runat = "server">
<Div>
<Asp: hyperlink id = "hyperlink1" runat = "server" navigateurl = "target. aspx"> Target </ASP: hyperlink> </div>
</Form>

The above two methods achieve the same results, but there is a major difference. The hyperlink server control can be programmed on the server side, and the target page can be dynamically changed based on the current status.
Note: The hyperlink control has no events, so you can only set the navigateurl attribute in other events, such as page_load.

2. Programming
Hyperlink redirects from one page to another completely controlled by the user. If conditions are added before the jump, it is easier to use programming.
UseCodeThe following methods can be used to redirect a page: Response. Redirect, server. Transfer, server. Execute

(1) response. Redirect
When you jump from page a to page B, all data stored in the internal control is lost. Therefore, page B cannot access the data submitted by page A. After the jump, the URL Information of the browser changes, however, data can be transmitted between pages through sessions, cookies, applications, and other objects.
Response. Redirect redirection occurs on the client, which involves two communications with the Web server.

(2) server. Transfer
Page a jumps to page B, and the control of page processing is also handed over. During the jump process, the stored information such as request and session remains unchanged, and the browser URL still saves the URL Information of page.
The redirection request of server. Transfer is carried out on the server. The client does not know that the server performs page conversion, so the URL remains unchanged.

(3) server. Execute
Server. the execute method allows the current page to execute another page on the same web server. After the execution of another page is completed, the control process is returned to the original page and the server is sent. where the Execute Command is called. The enableviewstatemac attribute of the called page command must be set to false;

 

Select the jump mode:

Hyperlink Server Control --------- the user determines when to convert, and the user determines the conversion time

Response. Redirect ------ When you need to link to another server and link to a non-ASPX page, you need to retain the query string as part of the URL

Response. Redirect and server. Transfer

From: http://blog.csdn.net/popule_daisy/archive/2008/09/10/2907304.aspx

1. browser aspx 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 aspx file request-> server execution-> server. Transfer statement-> server redirection to new file

Switch object:

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

2. server. Transfer can only switch to a webpage in the same directory or subdirectory.

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

====================

Lovehongyuan's summary:

 

Server. Transfer:
For the current request, terminate the execution of the current page and start executing the new page using the specified URL path pointing to a new page.

The transfer page should also be a. ASPX page. For example, transfer to. asp or. asmx page is invalid. The transfer method retains the querystring and form sets.

Transfer calls the end, which causes a threadabortexception exception upon completion.

ASP. NET does not verify whether the current user has the right to view resources submitted by the transfer method. Although ASP. NET authorization and authentication logic run in the Process of calling the original resourceProgramPreviously, ASP. NET still directly calls the handler indicated by the transfer method, and does not re-run the authorization and authentication logic for the new resource. If the application's security policy requires the client to have proper authorization to access the corresponding resources, the application should force re-authorization or provide a custom access control mechanism.

------------------------------------------------------------------
Response. Redirect:

Redirects the client to a new URL and specifies the new URL.
The redirect method executes client redirection. In this case, the browser requests a new resource. This redirection is a new request to enter the system. Therefore, it must undergo all authentication and authorization logic tests for Microsoft Internet Information Service (IIS) and ASP. NET security policies.

 

Another article compares the differences between response. Redirect and server. TransferArticle

Most people use response. Redirect to direct users to another page, while others seem to prefer the mysterious server. Transfer. What is the difference between response. Redirect and server. transfer?

Response. Redirect simply sends a message to the browser, telling the browser to locate another page. You can use the following code to direct the user to another page:

Response. Redirect ("webform2.aspx ")

Or

Response. Redirect ("http://www.zhisi.net /")

Server. Transfer also uses one statement to direct the user to another page, for example, server. Transfer ("webform2.aspx "). However, this statement has a series of unique advantages and disadvantages.

First, use server. transfer directs to another page to reserve server resources. By changing the server's "Focus" and transmission request, it will tell the browser to redirect, which means that you will not occupy a large number of HTTP requests, therefore, this can reduce the pressure on the server and make your server run faster.

However, please note that because "transfer" can only run between the same site on the same server end, you cannot use server. Transfer to redirect users to the site on another server. Only response. Redirect can redirect to a site other than the server.

Second, server. transfer retains the URL address of the browser. This is helpful for streamlined data input, but it also increases the debugging complexity.

Also, the server. transfer method has another parameter -- "preserveform ". If you set this parameter to true, for example, server. Transfer ("webform2.aspx", true), querystring and any form variables will be passed to the page you are located at the same time.

For example, webform1.aspx has a text box named textbox1, which is passed to webform2.aspx using preserveform to true. You can still use request. Form ("textbox1") to obtain the value of the text box.

This technology is useful for wizard-type multi-page input, but here you must note that when you use the preserveform parameter, Asp. net has a bug. Normally, an error occurs when attempting to pass the form or querystring value. See: http://support.microsoft.com/default.aspx? Id = KB; en-US; q2017920

The unofficial solution is to set the enableviewstatemac attribute to true on the target page you want to pass, and then set it back to false. This indicates that you need to use the false value of enableviewstatemac to solve this problem.

Conclusion: Response. Redirect simply tells the browser to access another page. Server. Transfer helps reduce server requests, keep the address bar URL unchanged, and allow you to pass querystring and form variables to another page (with a small flaw ).

Important: do not confuse the server. transfer and server. execute, server. execute to execute a page and return the result. execute is very useful, but in ASP.. net, it is replaced by the fresher method, so ignore server. execute.

In addition

Execution Process

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 redirection to new files

Switch object

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

2. server. Transfer can only switch to a webpage in the same directory or subdirectory.

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

Transmitted data volume (parameters attached to the URL)

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

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

 

 

 

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.