Solved

Server.Transfer

Posted on 2008-10-12
9
1,510 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
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
 
LVL 8

Author Comment

by:rpkhare
ID: 22700589
What about the answer to question 2 in my original post?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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:Tiggerito
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Handle null when using linq in this line 1 26
Why don't I see this table in EDMX file? 2 23
Different Delete Messages 7 37
Jquey and footrable 2 35
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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

13 Experts available now in Live!

Get 1:1 Help Now