What's the difference between Response.Redirect and Server.Transfer?

  • Thread starter Thread starter Alan Silver
  • Start date Start date
A

Alan Silver

Hello,

Sorry if this is a stupid question, but I can't really see much
difference between these tow methods according to the scant info in the
SDK.

Could anyone enlighten me? TIA
 
Sorry if this is a stupid question, but I can't really see much
difference between these tow methods according to the scant info in
the SDK.

Server.Transfer does a server side transfer.

Response.Redirect does a client side redirect - the server informs the
browser to redirect.

So here's the flow:

Server Transfer

1. Client Request Page HelloWorld.ASPX
2. Server.Transfer -> Server send a different page to the client
3. Client Receives Page still thinking it's HelloWorld.ASPX.
4. Client's URL (Address bar) remains HelloWorld.ASPX since the page was
sent on the server side and the client doesn't know a different page was
sent.

Response.Redirect

1. Client Requests Page HelloWorld.ASPX
2. Response.Redirect -> Server sends a HTTP header informing that the
user should redirect. 3. Client sees the redirect notice and requests
AnotherPage.ASPX 4. Server sends AnotherPage.ASPX
5. Client's URL (address bar) shows AnotherPage.ASPX

Technically speaking, Server.Trasfer is faster since there 1 less
roundtrip, but you lose the URL of the page. Server.Transfer also allows
for more flexibilty since you can use HTTPContext.Items to pass
variables beteen pages.

However, I only use Server.Transfer when i need to pass context items.
Otherwise I use Response.Redirect so the user will always see the
correct URL in the address bar.
 
Also, after a server.transfer, Context.Handler will refer to the initial
page, with no way of getting the new page (as far as i know)...certainly a
pita when you run into it and didn't know :)

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
 
Thanks, that was a very clear answer.
Server.Transfer does a server side transfer.

Response.Redirect does a client side redirect - the server informs the
browser to redirect.

So here's the flow:

Server Transfer

1. Client Request Page HelloWorld.ASPX
2. Server.Transfer -> Server send a different page to the client
3. Client Receives Page still thinking it's HelloWorld.ASPX.
4. Client's URL (Address bar) remains HelloWorld.ASPX since the page was
sent on the server side and the client doesn't know a different page was
sent.

Response.Redirect

1. Client Requests Page HelloWorld.ASPX
2. Response.Redirect -> Server sends a HTTP header informing that the
user should redirect. 3. Client sees the redirect notice and requests
AnotherPage.ASPX 4. Server sends AnotherPage.ASPX
5. Client's URL (address bar) shows AnotherPage.ASPX

Technically speaking, Server.Trasfer is faster since there 1 less
roundtrip, but you lose the URL of the page. Server.Transfer also allows
for more flexibilty since you can use HTTPContext.Items to pass
variables beteen pages.

However, I only use Server.Transfer when i need to pass context items.
Otherwise I use Response.Redirect so the user will always see the
correct URL in the address bar.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top