Server.Transfer VS. Response.Redirect
-
Hello All, I have an ASP.NET app with about 5 or 6 aspx pages. I have a starting page and allow the user to select items from a list box and I carry these items from page to page using Session["whatever"] = "blah". I am trying to make my application run as fast as possible and was wondering which method of page changing is faster? Server.Transfer or Response.Redirect. Any advice you could give would be much appreciated. Thanks for helping out a newbie! Frank
-
Hello All, I have an ASP.NET app with about 5 or 6 aspx pages. I have a starting page and allow the user to select items from a list box and I carry these items from page to page using Session["whatever"] = "blah". I am trying to make my application run as fast as possible and was wondering which method of page changing is faster? Server.Transfer or Response.Redirect. Any advice you could give would be much appreciated. Thanks for helping out a newbie! Frank
-
Hello All, I have an ASP.NET app with about 5 or 6 aspx pages. I have a starting page and allow the user to select items from a list box and I carry these items from page to page using Session["whatever"] = "blah". I am trying to make my application run as fast as possible and was wondering which method of page changing is faster? Server.Transfer or Response.Redirect. Any advice you could give would be much appreciated. Thanks for helping out a newbie! Frank
Technically,
Server.Transfer
is not a page redirect.Response.Redirect
sends the HTTP Location: header to redirect the browser to a different page. Conversely,Server.Transfer
executes the page code from a different page that is output to the client as though it was the page they request. The browser is not redirected at all. So, the question of which one is faster isn't really relevent. It's all based on your implementation of whether or not you want the client browser to be redirected to another page or - in some sense - have the server do it.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
Hello All, I have an ASP.NET app with about 5 or 6 aspx pages. I have a starting page and allow the user to select items from a list box and I carry these items from page to page using Session["whatever"] = "blah". I am trying to make my application run as fast as possible and was wondering which method of page changing is faster? Server.Transfer or Response.Redirect. Any advice you could give would be much appreciated. Thanks for helping out a newbie! Frank
Heath is right, they serve different purposes. Also note you cannot have querystring data in a
Server.Transfer
. regards, Paul Watson Bluegrass South Africa Brian Welsch wrote: "blah blah blah, maybe a potato?" while translating my Afrikaans. Crikey! ain't life grand? -
Heath is right, they serve different purposes. Also note you cannot have querystring data in a
Server.Transfer
. regards, Paul Watson Bluegrass South Africa Brian Welsch wrote: "blah blah blah, maybe a potato?" while translating my Afrikaans. Crikey! ain't life grand?If you specify, the query string and any form data can be passed along during the transfer. Provided it has any relevance to the new page of course. Server.Transfer("newpage.aspx", true);
-
If you specify, the query string and any form data can be passed along during the transfer. Provided it has any relevance to the new page of course. Server.Transfer("newpage.aspx", true);
What I meant was you can't go
Server.Transfer("newpage.aspx_?var1=val1&var2=val2_", true);
like you can withResponse.Redirect
. But thanks for the info, I knew it transferred form collection data but not existing querystring data. regards, Paul Watson Bluegrass South Africa Brian Welsch wrote: "blah blah blah, maybe a potato?" while translating my Afrikaans. Crikey! ain't life grand? -
Technically,
Server.Transfer
is not a page redirect.Response.Redirect
sends the HTTP Location: header to redirect the browser to a different page. Conversely,Server.Transfer
executes the page code from a different page that is output to the client as though it was the page they request. The browser is not redirected at all. So, the question of which one is faster isn't really relevent. It's all based on your implementation of whether or not you want the client browser to be redirected to another page or - in some sense - have the server do it.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
To add to Heath's reply, the evidence of this is in the address bar. If you use a Server.Transfer you will see the address of the page has not changed, due to the fact that processing has stopped on the original page and transferred to the new page. Conversely, if you use Response.Redirect you will see the address of the new page in the address bar. Not sure if this matters but it may be relevant. Just because I don't care, doesn't mean I don't understand. - Homer J. Simpson