Some users prefer response. Redirect while others prefer server. Transfer. Most of the time, it seems that both methods can implement the same function. Is there a difference?
I checked some documents and found that the difference between the two is quite obvious. Basically, response calls the browser to redirect to the specified webpage, and the server naturally occurs on the server side, so there are the following differences:
1. server. Transfer can only jump to the page specified by the local virtual directory, while response. Redirect is very flexible;
2. server. Transfer can easily pass the page parameters to the specified page;
3. When server. Transfer jumps to another page during use, the address displayed by the browser will not change, and sometimes it will lead to misunderstanding. Of course, this effect is also required in some occasions;
4. server. Transfer can reduce client requests to the server;
==============================================
Ransfer:
Reliable Programming
The target page of the transfer should be another web form page (. ASPX page) in the same application ). You cannot use server. Transfer to redirect to The. asp or. asmx page.
Make sure that the target page exists.
Because server. Transfer is executed on the server, there is no page change record in the browser. Therefore, if you refresh this page, unexpected results may occur.
Redirect:
Reliable Programming
The redirect method is executed through the browser, so an additional round-trip process is generated between the server and the browser.
Make sure that the target page exists.
Security
Because this method is executed through the client, it is prone to spoofing and tampering.
========================================================== =
The status of the server. Transfer jump page is similar to that of response. Redirect.
However, there are still some differences between them.
First, use server. Transfer to migrate to another page to maintain service resources.
Instead of simply notifying the Browser Server to change pages and migrate requests. This
This means that you do not need to carry more HTTP requests, so it can reduce
And make your application run faster.
However, note: because the "transfer" process can only be performed on
You cannot use server. Transfer to redirect users to external sites.
Only response. Redirect can achieve this.
Second, server. Transfer maintains the original URL of the browser.
Data entry technology, although it may cause data confusion during debugging
Also, the server. transfer method has two parameter overload methods --
"Preserveform" if you set it to true (false by default ),
Use a status such as server. Transfer ("webform2.aspx", true ),
The existing request string and all the variables in the form will be kept and submitted to your
Target page.
However, it must be noted that there is a strange bug (Why does Microsoft have such a bug?
). When you try to migrate form and request characters using the overload method of Two Parameters
Errors may occur during the string.
The unofficial solution is to enableviewstatemac of the screen to be redirected.
And then set it back to false.