Right now I am reading about .net website performance and scalability.
I read many blog posts and microsoft book about performance and scalability.
In last blog, linked here.
In this blog poing no.6 talking about
"Use HTTPServerUtility.Transfer instead of Response.Redirect"..
Is it more useful in performance of website and to the point as in the blog that,
"They should only be used when you are transferring people to another physical web server. For any transfers within your server, use .transfer! You will save a lot of needless HTTP requests."
Anyone help me how it is more useful in performance than response.redirect?
You should not just blindly start using Server.Transfer
instead of Response.Redirect
; they are not simply drop-in replacements.
Server.Transfer
has another page 'take up' execution where the current one leaves off, giving its output. This saves the Redirect step - A redirect issues a 302 - Moved
response to the client, with the new URL to load, then the browser makes that new request. That is what is being 'saved' when you use Server.Transfer
instead.
But you can also lose things; Like, your user can become confused when they try to bookmark a page that loaded with a Server.Transfer
involved, and find something totally unexpected showing up because Server.Transfer
was not used with that eventuality in mind.
You also have to do a little bit of work to make sure you get your request values marshalled over to the 'new' page properly; query string, form values, and the values of server-side controls.
I would call Server.Transfer
something to consider when you are more advanced and knowledgeable of the ASP.NET pipeline and the HTTP protocol, and basically... you don't have any question at all when/why you would want to use it.
EDIT: Also; I would not take anything you read on that web site you link too seriously at all. The writer says that you should avoid server-side validation and instead only do it on the client. That, and many of their own recommendations show an extremely limited knowledge of ASP.NET/HTTP. Don't let someone like that make you spend so much time on something so unimportant.
Yeah Server.Transfer
eliminate Http Request; however, its not best suited in all scenarios. You should know what each do.
Response.Redierct
Response.Redirect
sends response with new URL to load having Response code 302 Moved.Server.Transfer
Server.Transfer
So in short you save one round trip with Server.Transfer. But the browser could not get new URL.
Conclusion: If you want to index your URLs by search engines or want your users to bookmark URLs then Server.Transfer
will not help you.
Server.Transfer: will only help you to hide URL from user or browser or search engines.
Server.Transfer is NOT more useful in performance. The better performance is depent from what actuall run in the page and where you call the transfer or the redirect, but the diferent are so small that you need to focus what actuall transfer
vs redirect
do.
Transfer
adds a lot of problems that
add to your navigation from page to
page, eg user see the same page name, but the content is diferent. Transfer
also can not handle
post back asp.net functions.transfer
you always need to know on each post back what page you show next because you always load the same code page. Transfer
, then server for every page need to load and run 2 different page code for the same result.Redirect
from the other hand is a method to navigate and show results to the processing of user input. Its clean, code on the second page work with out problems, postback and all that work the same.
I suggest to anyone to rare use the Server.Transfer
.
Here is an example that Transfer make thinks complicate and slower. If you have a work to do, and then show result, and lets say that this work makes some seconds, if you make Transfer, on every post back, or reload the work must be run again !.
protected void Page_Load(object sender, EventArgs e)
{
// function works
Thread.Sleep(10000);
Server.Transfer("Page2.aspx");
}
Second Case with redirect, the work will be done one time and not called again, user moves to the result page.
protected void Page_Load(object sender, EventArgs e)
{
// function works
Thread.Sleep(10000);
Response.Redirect("Page2.aspx");
}
I think, that there is no need for too many talks, if you practice them a little you can see many thinks and different in real pages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With