Server.Transfer vs. Response.Redirect

T

Terry Olsen

Since both methods seem to produce the same results, in which cases
would you prefer one over the other? The only thing I would think is
using Server.Transfer because of some browsers blocking redirects.
 
P

Patrice

Response.Redirect tells the client the new URL that should be hit.

Server.Transfer is server side and the client doesn't know the new location
which could be a problem.

Still I've got mayself a hard time to find out a legitimate use for
Server.Transfer / Server.Execute. I always thought it's here mainly for
legacy as it always looks like to me the reason is that you embedded some
processing in a particular ASPX page which is not especially desirable ?

Hopefully someone will pop up with a legitimate use I didn't thought
about...

Patrice
 
E

Eliyahu Goldin

Server.Transfer saves you one round trip to the client. As a result, client
is unaware of the transfer and keeps showing original url in its url field
which is misleading. Just one of the considerations.

Eliyahu
 
S

Steve C. Orr [MVP, MCSD]

Response.Redirect requires an extra round trip between the browser and the
server, therefore it is less efficient. However, at least this keeps the
browser informed of what's going on so it can display the correct URL in the
address bar.
Server.Transfer is more efficient, and it masks the true URL of the page
from the browser, which can be a good thing sometimes but is more often a
hassle (such as when the user reloads the browser page and the browser then
requests the wrong page.)
 
G

Guest

Using the Transfer method is very similar to executing a hyperlink or using
the Redirect method, with one difference: Transfer can retain some
information from the source page across requests. Setting the Transfer
method' s preserveForm argument to True makes the form' s QueryString,
ViewState, and event procedure information available in the destination form.

To use the Transfer method with preserveForm set to True, you must first set
the EnableViewStateMac attribute in the Web form' s Page directive to False.
By default, ASP.NET hashes ViewState information, and setting this attribute
to False disables that hashing so the information can be read on the
subsequent Web form.

And You can't use the Transfer method with HTML pages. It works only with
..aspx pages. For example, Request.Redirect(“my_html.htmâ€) is right but
Server.Transfer(“my_html.htmâ€) is wrong.

HTH

Elton Wang
(e-mail address removed)
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top