Register now or log in to join your professional community.
which one is better ?
Response.Redirect should be used when:
we want to redirect the request to some plain HTML pages on our server or to some other web server
we don't care about causing additional roundtrips to the server on each request
we do not need to preserve Query String and Form Variables from the original request
we want our users to be able to see the new redirected URL where he is redirected in his browser (and be able to bookmark it if its necessary)
Server.Transfer should be used when:
we want to transfer current page request to another .aspx page on the same server
we want to preserve server resources and avoid the unnecessary roundtrips to the server
we want to preserve Query String and Form Variables (optionally)
we don't need to show the real URL where we redirected the request in the users Web Browser
Response.Redirect(....);To redirect the page to any specified URL. you may loose your context after redirection as if you redirect to someother domain. (as described by Mr. M. Asim as well)Server.Transfer(....);To transfer the request to another page residing onto same WebServer. It is too fast as server hasn't to lacate it in a huge DNS but do look for it locally. Other than thins you may notice that the URL in the address bar doesn't get updated to the new page but remain showing the address of caller page. I think it was best option in the scenario where you run some king of wizard i.e. the account creation wizard. Alternate to which now you can use MultiView as well.
‘Response.Redirect’ sends message to the browser saying it to move to some different page,while server. Transfer does not send any message to the browser but rather redirects the userdirectly from the server itself. So in ‘server.transfer’ there is no round trip while‘response.redirect’ has a round trip and hence puts a load on server.Using ‘Server.Transfer’ you cannot redirect to a different from the server itself. Example if yourserver is www.yahoo.com you can not use server.Transfer to move to www.microsoft.com butyes, you can move to www.yahoo.com/travels, i.e. with in websites. Cross server redirect ispossible only by using Response. Redirect.With ‘server.transfer’ you can preserve your information. It has a parameter called as“preserveForm”. Therefore, the existing query string etc. will be able in the calling page.
Server.Transfer is better if you are moving in same directory from one page to another. It prevent from the extra round trip on the server whereas Response.Redirect is best if you are navigating to an external domain. Response.Redirect sends the request on server and then get the response to navigate on to specific url.