Solved

Server.Transfer

Posted on 2008-10-12
9
1,509 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
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 5

Accepted Solution

by:
varungd earned 25 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 8

Author Comment

by:rpkhare
Comment Utility
What about the answer to question 2 in my original post?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 7

Expert Comment

by:ajolly
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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:Tiggerito
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now