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

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
 
L

Lucas Tam

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.
 
A

Alan Silver

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

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top