Sunday, 22 December 2013

Difference between Server.Transfer and Response.Redirect

Hi ,In  this article we are going to see the difference the usage of Response.Redirect and Server.Transfer, Both are used to change the our current webpage and launches a another one in browser.

Response.Redirect :
It is used to redirect the user from one page to other webpage.
Redirection can be done for the webpage present with in the server or in the Web

First paramter is the string to specify the redirect address, second parameter is the bool which will specifies whether engine has to execute the remaining line of code after the redirect. if it false then the remain code which is present after the line of redirection will not execute.


 Response.Redirect("WebForm1.aspx",true); -- code after this line execute by engine.


Server.Transfer :
It is used to transfer the current and launches the new web page with out changing the url in the web browser.
It can able to redirect the pages which are present with in the server or application

First parameter is a string which is specify the url of the webpage to redirect.,Second parameter is a boolean to specify whether we have to preserve the form, i.e in the launch of next webpage we have a property called Form in the Request object , if the second parameter is true then the Form property will have the previous page and there control values.



Server.Transfer("",true);  -- this line will execute and raise error because google is not in the server it is the web host application

I Hope this article will help you to understand, how and where to use the both the methods.

No comments:

Post a Comment