im having confusion with which one is better or effect for request of calling page(first page) and caller page (new page) ...
i notice that 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.
any comments appreciable ....
Response. Redirect simply sends a message (HTTP 302) down to the browser. Server. Transfer happens without the browser knowing anything, the browser request a page, but the server returns the content of another.
Because a redirect forces a new page request, the browser makes two requests to the Web server, so the Web server handles an extra request. IIS 5.0 introduced a new function, Server. Transfer, which transfers execution to a different ASP page on the server.
Transfer(String, Boolean) Terminates execution of the current page and starts execution of a new page by using the specified URL path of the page. Specifies whether to clear the QueryString and Form collections. public: void Transfer(System::String ^ path, bool preserveForm); C# Copy.
Redirect servers: A redirect server processes all proxy server requests and performs call re-routing for User agents. • Registrar servers: A registrar server is responsible for registering User agents. It sends the logged information about the UA to the location server for administrative purposes and future requests.
Original at : Difference between Server.Transfer and Server.Execute
Both Server.Transfer and Server.Execute were introduced in Classic ASP 3.0 (and still work in ASP.NET).
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.
I know this is old but it came up as the 1st or 2nd hit when I searched on google. I did some testing and wanted to post the results.
I created a website with 2 pages. Page Load on the 1st page contained the code..
try { //Response.Redirect("~/WebForm2.aspx"); //Server.Transfer("~/WebForm2.aspx"); //Server.Execute("~/WebForm2.aspx"); //Server.TransferRequest("~/WebForm2.aspx"); string strTry = "Try"; } catch (Exception ) { string strCatch = "Catch"; } finally { string strFinally = "Finally"; }
The sequence of what it did for each is what 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 to know what order you like things to occur in.
Personally I like the idea of the current code finishing, BEFORE the next page's code starts. So either Redirect or TransferRequest, although with the latter, you may have to add a "return" just below your call if you really intended for it not to execute the rest of the try block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With