ASp.Net day

Micro blog



About Satalaj

www.satalaj.com

The best inline translator

Live lookup to see what asp.net developers are searching





Server.Transfer vs Response.Redirect       by Satalaj 21. January 2010 10:50
    

 Use Server.Transfer. whereever it is possible, use the Server.Transfer method instead of the Response.Redirect method.
Response.Redirect sends a response header to the client that causes the client to send a new request to the redirected server by using the new URL.
If you have tools installed like fiddler you can easily see what has been posted back inside Header to the clients like IE.
Its a Status code 302 and header contains location of resource.

 Server.Transfer avoids this level of redirection by simply making a server-side call.
You cannot always just replace Response.Redirect calls with Server.Transfer calls because Server.Transfer uses a new handler during the handler phase of request processing.
If you need authentication and authorization checks during redirection, use Response.Redirect instead of Server.Transfer because the two mechanisms are not equivalent and
as you know during authontication we check wheather cookie exists in Request or not. There we must use Response.Redirect.

When you use Response.Redirect, ensure you use the overloaded method that accepts a Boolean second parameter, and pass a value of false to ensure an internal exception is not raised.

You can see that exception by simply putting Try catch Blocks in your application. To avoid internal exception pass second parameter as false.

Also note that you can only use Server.Transfer to transfer control to pages in the same application. To transfer to pages in other applications, you must use Response.Redirect.

That means you can't call the pges residing outside of your application domain. like
http://bing.com  http://google.com www.asp.net can't put inside your server.transfer method.

Satalaj

     

Add comment


 

biuquotecode
Loading