Articles → .NET → Difference Between Response.Redirect And Server.Transfer
Difference Between Response.Redirect And Server.Transfer
- Visual Studio 2008 or Visual Studio 2005 installed on your computer.
- Hands on experience on creating a web application.
Creating a web application
- Create ASP.NET web application with C# as programming language with name WebApp1.
- Add 2 pages page1.aspx and page2.aspx
- On page1.aspx add a textbox (TextBox1) and 2 button controls i.e. Button1 and Button2.
- In case of Server.Transfer you cannot send the user to external sites but by using Response.Redirect you can send the user to external site.
|"Button 1" click||Page is navigated to http://www.gyansangrah.com.|
|"Button 2" click||Invalid path for child request 'http://www.gyansangrah.com'. A virtual path is expected.|
- Server.Transfer maintains the original URL in the browser.
|"Button 1" click||http://localhost/WebApp1/Page2.aspx|
|"Button 2" click||http://localhost/WebApp1/Page1.aspx|
- Server.Transfer saves server resources.
|"Button 1" click||Page is redirected to Page2.aspx and on the page Testing444 is written|
|"Button 2" click||URL doesn’t change but page is redirected to Page2.aspx and on the page Testing123 and Testing444 is written|
- You can access the contents of previous page using Server.Transfer, but not in case of Response.Redirect.
- If PreserveForm Paramater in Server.Transfer is set to true then you can access the values of controls by using Request.Form