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 followingCodeDirect 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 Executes a page and returns 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.
This article is reproduced; original address http://webservices.ctocio.com.cn/net/188/8900188.shtml
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 Executes a page and returns 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.
This article is reproduced; original address http://webservices.ctocio.com.cn/net/188/8900188.shtml