Solved

Server.Transfer

Posted on 2008-10-12
9
1,517 Views
Last Modified: 2012-06-27
I searched Google to find difference between Response.ReDirect and Server.Transfer. I found many links but articles are confusing. It is still not very clear:

(1) In which situations to use Server.Transfer?
(2) When the page is about to restore its view state and during that time the connection with the server breaks, what will happen? Will the view state be successfully restored?
(3) Does Response.Redirect refreshed memory on each call and it is not possible to access last page contents?
0
Comment
Question by:rpkhare
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 5

Accepted Solution

by:
varungd earned 25 total points
ID: 22700358
Use below given  codes and check your URL after redirect the page. You can understand the difference. While using Server.Transfer URL is not updating.

Response.Redirect("Webform1.aspx");
Server.Transfer("Webform1.aspx");
0
 
LVL 8

Author Comment

by:rpkhare
ID: 22700413
Ok that I have experimented. What are the specific situations where Server.Transfer is to be used?
0
 
LVL 7

Assisted Solution

by:ajolly
ajolly earned 25 total points
ID: 22700530
1. Server.Transfer does not update the URL in the address bar, so you should not use it when you want the URL to be the URL of the page where you are.

2. Server.Transfer is faster than Response.Redirect. So if you need the faster response and you don't worry about point 1 then use Server.Transfer.

3. Server.Transfer can not transfer to the different server. You can not use Server.Transfer to transfer from your page to yahoo.com or somewhat like that. But Response.Redirect can redirect you to any valid URL.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Author Comment

by:rpkhare
ID: 22700589
What about the answer to question 2 in my original post?
0
 
LVL 7

Expert Comment

by:ajolly
ID: 22700622
its an atomic process.
its done fully or not at all. If you viewstate data was transferred to the server fully, it will not save. If it is transferred to the server and then the link breaks, not an issue, it will be saved.
0
 
LVL 13

Assisted Solution

by:TechTiger007
TechTiger007 earned 25 total points
ID: 22701253
The real difference between server.transer and response.redirect is this
When you call Response.Redirect your source code will stops execution and sends a response to the web browser to open the redirect URL specified. So your browser will update the URL displayed and sends a new request to the URL. So in this case there is an extra round trip or request

When you call server.transfer, asp.net will stop execution of the current page and start processing the page in new URL and send the response back to the web browser. So the browser is unaware of a change in URL here Hence the URL is not updated. There is no extra round trip in this case.

Since an asp.net process can execute code which is under the same site, you can use server.transfer to transfer control to any page within that site.
In case of Response.Redirect you are just saying the browser to open a new page, hence you can give any URL here.

Hope that clarifies
0
 
LVL 8

Author Comment

by:rpkhare
ID: 22701339
In my site, I am using SiteMap to display menu and from there accessibility to various web pages. In this case how to use Server.Transfer? I think it is using Response.Redirect by default. See the attached code:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="MenuPage.aspx" title="Main Menu"  description="Menu Page">
      <siteMapNode url="" title ="Masters" description="Master Settings">
        <siteMapNode url="ItemMaster.aspx" title="Item Master"  description="" />
        <siteMapNode url="PartyMaster.aspx" title="Party Master"  description="" />
        <siteMapNode url="CategoryMaster.aspx" title="Category Master"  description="" />
      </siteMapNode>
      <siteMapNode url="" title="Tasks"  description="">
        <siteMapNode url="" title="New Bill"  description="" />
        <siteMapNode url="" title="Stock Entry"  description="" />
      </siteMapNode>
    </siteMapNode>
  
</siteMap>

Open in new window

0
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22701514
This will not be using Server.Transfer or Response.Redirect. Your browser will be sending a new request to server. Response.Redirect or Server.Transfer will be useful when you are already processing a page in your code behind and in the middle of execution you decide to pass the control to another page based on some value (query string, database entry, etc)


0
 
LVL 23

Expert Comment

by:Tony McCreath
ID: 22701635
Server.Transfer does not support querystrings in the transfer url.

There are ways around this, but nothing nice as far as I know.

It can make it quite hard to use as a redirect tool.

Another related method is to use HttpModules and url mapping.

Could you clarify how you plan on using your sitemap and why you feel redirects or transfers are needed.
 
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question