views:

2818

answers:

4

I understand they both don't change the URL that the client sees. Is there anything in them that makes one of them preferable over the other?
I'm planning to use it in the Application_BeginRequest in Global.asax, but also in regular aspx page.

+4  A: 

Context.RewritePath i think it is a better option. Reason:

-Note that Server.Transfer throws a ThreadAbortException every time. Well, it's the result of calling Response.End.

Look here:

http://support.microsoft.com/kb/312629

http://msdn.microsoft.com/en-us/library/aa332847.aspx

EDIT: (I have investigated and Server.Transfer does not send a HTTP 302 redirect command as Response.Redirect would do).

As they say (http://msdn.microsoft.com/en-us/library/system.web.httpcontext.rewritepath(VS.71).aspx) RewritePath is used in cookieless session state.

The differences bt Server.Transfer and Server.Execute are big ones, in fact, there are not the same thing at all:

-with Server.Execute Once code execution gets over, the control returns to the initial page, just after where it was called. That is to say I can do the following:

  <div>
       test 1 <br/>
        <% Server.Execute("include.aspx?hello=ok"); %>
       test 2 <br/>
    </div>

This would write: test 1 , the content of the url, test 2

netadictos
+1  A: 

Context.RewritePath Assigns an internal rewrite path and allows for the URL that is requested to differ from the internal path to the resource. RewritePath is used in cookieless session state.

Whereas Server.transfer transfers the content assembled for processing of one page to another page .

Samiksha
+1  A: 

To avoid the exception thrown by Server.Transfer, you can use Server.Execute. Both Server.Transfer and Server.Execute DO NOT issue an 302 HTTP message. Only Response.Redirect issues this header and asks the browser to go to the new destination, claiming that it was temporarily moved. Both Server.Transfer and Server.Execute allow you to execute a different page to service current request.

Sergiu Damian
+1  A: 

I find this link interesting.

Server.Transfer Vs. Response.Redirect

rajesh pillai