In this programming tutorial we will learn the difference between server.transfer and response.redirect. Server and Response both are objects in ASP.NET use for redirecting the users from one page to another or from one website to another website. Server object provides methods and properties for various tasks related to a server. Transfer is a method of the Server object and it sends information of the current state to another .aspx file for processing. Response object describes methods and properties related to a server’s response. Redirect is a method of the Response object and it sends a message to the browser making it connect to a different URL. Although both the Server.Transfer and Response.Redirect can be used to transfer a user from one page to another yet they are different to each other.
What is Response.Redirect?
Redirect is a method of the Response object. When the Response method is called, it sends the HTTP code 302 and the URL of the requested web page to the user's browser. The HTTP code 302 informs the user’s browser that the requested resource is located under a different URL. So when the browser receives the code, it instantly opens the resource in the new location. The requested web page can reside on the same server (Same Website) as the page that contained the request or it could be located in some other server (Some other website). When requesting a web page residing on the same server, Response method can be used as follows:
When requesting a web page residing on another server (another website), Response method can be used as follows:
What is Server.Transfer?
Transfer is a method of the Server Object. When the Transfer method is called, the original request is modified to transfer in to some other page in the same server. When a new page is requested using the Server.Transfer, URL shown in the user’s browser does not change. This is because the transfer happens in the server side and the browser does not have any knowledge about the transfer. If we use the second overload for Server.Transfer(string path, bool preserveForm) and sets the second parameter as true, posted form variables and query strings can be made available to the second page.
Difference between Server.Transfer and Response.Redirect
So that's it. I hope you know better understand the difference between Response.Redirect and Server.Transfer.
I love your feedback.
Redirect is a method of the Response object. When the Response method is called, it sends the HTTP code 302 and the URL of the requested web page to the user's browser. The HTTP code 302 informs the user’s browser that the requested resource is located under a different URL. So when the browser receives the code, it instantly opens the resource in the new location. The requested web page can reside on the same server (Same Website) as the page that contained the request or it could be located in some other server (Some other website). When requesting a web page residing on the same server, Response method can be used as follows:
Response.Redirect(“Welcome.aspx”);
When requesting a web page residing on another server (another website), Response method can be used as follows:
Response.Redirect(“http://www.yourwebsite.com/Welcome.aspx”);
What is Server.Transfer?
Transfer is a method of the Server Object. When the Transfer method is called, the original request is modified to transfer in to some other page in the same server. When a new page is requested using the Server.Transfer, URL shown in the user’s browser does not change. This is because the transfer happens in the server side and the browser does not have any knowledge about the transfer. If we use the second overload for Server.Transfer(string path, bool preserveForm) and sets the second parameter as true, posted form variables and query strings can be made available to the second page.
Difference between Server.Transfer and Response.Redirect
- Response.Redirect can be used to redirect the user to a web page in another server (another website) whereas Server.Transfer can only be used to redirect the user to web pages on the same server (same website).
- Response.Redirect makes a roundtrip to the server, while Server.Transfer changes the focus of the web server to a different web page. Therefore, by using Server.Transfer we can save server's resources.
- Transfer, properties of the previous page can be accessed from the new page but this is only possible with server.transfer.
- Finally, Response.Redirect changes the URL in the address bar of the browser when the new page is accessed but when using the Server.Transfer the original URL is retained and the content of the page is just changed. So the user cannot use it to bookmark the new page as it always refer to the first content that comes with that url.
So that's it. I hope you know better understand the difference between Response.Redirect and Server.Transfer.
I love your feedback.
0 comments:
Post a Comment