Which one is better Server.Transfer and Response.Redirect

Which one is better, Server.Transfer or Response.Redirect ? I am looking for an explanation for this.

+2
source share
2 answers

They have different functions. Determining the best depends on what you are trying to do.

Response.Redirect informs the client about visiting a new address, which could be anywhere.

Server.Transfer redirects the request (optionally saving the query string) to another page on the same server.

If your criterion reduces unnecessary overhead, given that the new page is on the same server, Server.Transfer is the method you want.

+9
source

It depends on your reqiremnts.

Suppose you are on page 1.aspx and want to go to page2.aspx

Response.Redirect script
page1.aspx calls Response.Redirect ("page2.aspx", false); which sends the redirect header 302 down to the client browser, informing it that the requested (page1.aspx) has been moved to page2.aspx, and the web application terminates. The client browser then sends a request to the web server for page2.aspx. IIS tells asp_wp.exe to process the request. asp_wp.exe (after authentication and execution of all other configuration tools that must be performed when a new request is received) creates an instance of the corresponding class for page2.aspx, processes the request, sends the result to the browser and exits. In this case, there is feedback on the server.

Server.Transfer script
page1.aspx calls Server.Transfer ("page2.aspx") ;. ASP.NET creates an instance of the appropriate class for page2.aspx, processes the request, sends the result to the browser, and exits.

Please note that Server.Transfer reduces the load on the client and server.

Server.Transfer is easier to code since you maintain your state. Information can be transmitted through an HTTP context object between pages, which eliminates the need to transfer information in a request or reload from a database.

Some limitations of Server.Transfer
It can work only on the same domains (on one server)
It bypasses any authentication on the page that you translate to

Now you can decide for yourself which one is best according to your requirements.

-1
source

Source: https://habr.com/ru/post/1391069/


All Articles