DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

What Round Trip Means in Response.Redirect()

ASP.NET developers are familiar with this method, but what exactly is the "round trip" that is taken when the method is called? We investigate.

Rahul Bansal user avatar by
Rahul Bansal
·
Dec. 24, 18 · Presentation
Like (3)
Save
Tweet
Share
19.39K Views

Join the DZone community and get the full member experience.

Join For Free

Every developer goes to an interview for future growth and the interviewer also asks the same basic questions, the developer provides the answer that they've read about and studied, but sometimes the interviewer changes the basic question in a tricky way.

The interviewer might ask, "What is the difference between Response.Redirect() and Server.Transfer()?" Then you will reply:

  • Response.Redirect() is useful when we want to go to the page of external websites, whereas Server.Transfer() is used for accessing the page of the internal websites or within the same server.
  • Response.Redirect() changes the URL but Server.Transfer() doesn't.
  • Response.Redirect() takes the round trip whereas Server.Transfer() doesn't.

But what will happen when the interviewer asks you another question based on your answer?

"What does round trip mean? Can you explain it, and how can I see it visually?"

Answer: In the case of Response.Redirect(), first send the request to the Browser with the "HTTP 302 Found" code then the Browser sends the request to the server and gets the response with "HTTP 200 Ok" from the server.

But what if I'm talking about Server.Transfer() that directly sends the request to the server and gets the response, "HTTP 200 Ok" from the server?

Let's check it out. 

Open Visual Studio 2015 and select "File" -> "New" -> "WebSite:" and fill in the WebSite name as "WebSite1."

WebSite

After creating the web site, I will create two pages named "Page1.aspx" and "Page2.aspx" for redirection from the first page to the second page.

Page1

For the identification, I have added some text on both pages as shown in the following screen shots.

Page1.aspx
Page1 aspx

Page2.aspx

Page 2 aspx

Now I will use both Response.Redirect() and Server.Transfer() on the "Page_Load" event of "Page1.aspx."

Response.Redirect()

It redirects to "Page2.aspx" from "Page1.aspx".

Code

public partial class Page1 : System.Web.UI.Page  
{  
   protected void Page_Load(object sender, EventArgs e)  
   {  
      Response.Redirect("Page2.aspx");  
   }  
}  

Network

When I run the "page1.aspx" page it redirects meto "Page2.aspx." To check the existence of the round trip, use the following procedure:

  • Open "Internet Explorer" and press "F12."
  • Click on the "Network" Tab.
  • Click on the "Start capturing" Button.

Start capturing and network
After running the page1.aspx file:

running the page1
As you can see in the above image, it went to page1.apsx with the "HTTP 302" code and then got the response from the server with the "HTTP 200" code with the round trip.

Server.Transfer()

It redirects to "Page2.aspx" from "Page1.aspx."

Code

public partial class Page1 : System.Web.UI.Page  
{  
   protected void Page_Load(object sender, EventArgs e)  
   {  
      Server.Transfer("Page2.aspx");  
   }  
}  

Code
When I run the "page1.aspx" page it redirects me to "Page2.aspx." To check the existence of the round trip, use the following procedure:

  • Open "Internet Explorer" and press "F12."
  • Click on the "Network" Tab.
  • Click on the "Start capturing" Button.

Internet ExplorerAfter running the page1.aspx file:

localhost
As you can see in the preceding image, the browser got the response from the server with the "HTTP 200" code without any round trips involved.

Reference

For HTTP Status Codes: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Trip (search engine)

Published at DZone with permission of Rahul Bansal, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Bye-Bye, Regular Dev [Comic]
  • 5 Factors When Selecting a Database
  • PHP vs React
  • Key Considerations When Implementing Virtual Kubernetes Clusters

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: