[ACCEPTED]-Server.Transfer() Vs. Server.Execute()-asp.net

Accepted answer
Score: 27

Original at : Difference between Server.Transfer and Server.Execute

Both Server.Transfer and 16 Server.Execute were introduced in Classic 15 ASP 3.0 (and still work in ASP.NET).

When 14 Server.Execute is used, a URL is passed 13 to it as a parameter and the control moves 12 to this new page. Execution of code happens 11 on the new page. Once code execution gets 10 over, the control returns to the initial 9 page, just after where it was called. However, in 8 the case of Server.Transfer, it works very 7 much the same, the difference being the 6 execution stops at the new page itself (means 5 the control isn't returned to the calling 4 page).

In both the cases, the URL in the 3 browser remains the first page URL (doesn't 2 refresh to the new page URL) as the browser 1 isn't requested to do so.

Score: 5

I know this is old but it came up as the 13 1st or 2nd hit when I searched on google. I 12 did some testing and wanted to post the 11 results.

I created a website with 2 pages. Page 10 Load on the 1st page contained the code..

try {

    string strTry = "Try";
} catch (Exception ) {
    string strCatch = "Catch";
} finally {
    string strFinally = "Finally";

The 9 sequence of what it did for each is what 8 was really interesting...

Command            Sequence               
Redirect           Call, Catch (ThreadAbortException), Finally, Load Page 2
Transfer           Call, Load Page 2, Catch (ThreadAbortException), Finally
Execute            Call, Load Page 2, Try (continues), Finally
TransferRequest    Call, Try (continues), Finally, Load Page 2

.. So it may help 7 to know what order you like things to occur 6 in.

Personally I like the idea of the current 5 code finishing, BEFORE the next page's code 4 starts. So either Redirect or TransferRequest, although 3 with the latter, you may have to add a "return" just 2 below your call if you really intended for 1 it not to execute the rest of the try block.

More Related questions