Hi friends,
Would you like to tell me what is the difference between server.transfer() and server.execute() in ASP.NET?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
AartiPosted Nov 16, 2011, 8:06 AM
1. Server.Execute:
Syntax: Server.Execute(Path)
The Execute method allows you to call another ASP page from inside an ASP page.
When the called ASP page completes its tasks, you are then returned to the calling
ASP page. The overall effect is very similar to a function or subroutine call.
Any text or output from the called ASP page will be displayed on the calling ASP page.
The Execute method is a more useful alternative to using server-side includes.
2. Server.Transfer:
Syntax: Server.Transfer (Path)
The Transfer method allows you to transfer from inside one ASP page to another ASP page. All of the state information that has been created for the first (calling) ASP page will
be transferred to the second (called) ASP page. This transfered information includes all
objects and variables that have been given a value in an Application or Session scope,
and all items in the Request collections. For example, the second ASP page will have the
same SessionID as the first ASP page.
Thanks.
Manoj SevdaPosted Nov 16, 2011, 6:40 AM
2) Response.Redirect involves a roundtrip to the server whereas Server.Transfer conserves server resources by avoiding the roundtrip. It just changes the focus of the webserver to a different page and transfers the page processing to a different page.
3) If you are using Server.Transfer then you can directly access the values, controls and properties of the previous page which you can't do with Response.Redirect.
4) Response.Redirect changes the URL in the browser's address bar. So they can be bookmarked. Whereas Server.Transfer retains the original URL in the browser's address bar. It just replaces the contents of the previous page with the new one.
5) Response.Redirect can be used for both .aspx and html pages whereas Server.Transfer can be used only for .aspx pages and is specific to ASP and ASP.NET.
6) Response.Redirect can be used to redirect a user to an external websites. Server.Transfer can be used only on sites running on the same server. You cannot use Server.Transfer to redirect the user to a page running on a different server.
Javeed M ShaikhPosted Nov 14, 2011, 11:45 AM
When Server.Execute is used, a URL is passed to it as a parameter, and the control moves to this new page. Execution of code happens on the new page. Once code execution gets over, the control returns to the initial page, just after where it was called.
However, in the case of Server.Transfer, it works very much the same, the difference being the execution stops at the new page itself (means the control isn't returned to the calling page).
In both the cases, the URL in the browser remains the first page URL (doesn't refresh to the new page URL) as the browser isn't requested to do so.