views:

484

answers:

3

Say in my 'Page_init()' of "a.aspx" i just have 'server.transferrequest("b.aspx").

This works great, displays the content for "b.aspx" and the browserurl still stays at "a.aspx".

Happy days.

However does anyone know how to see this url from my "b.aspx" (the resulting page)?.

The usual request.rawurl and request.url.absoluteuri both return the current page as "b.aspx".

A: 

Server.TransferRequest Performs an asynchronous execution of the specified URL. This means that your client has no clue of was is going on at the server so from your client perspective it's the same page.

If you need to change the actual page (which is the most common) then use Response.Redirect.

Sergio
I need to keep the original url the same though.
maxp
The only option I see is to save it as a hiddenField. There is no direct way of achieving this.
Sergio
+1  A: 

Maybe before you do the transfer you could save the information you need somewhere, then retrieve it when it's needed again.

John Boker
storing it in the session. not elegant at all though.
maxp
A: 

You can use PreviousPage to get source page that makes server transfer :

string previousPagesUrl = PreviousPage.Request.RawUrl;

EDIT : @maxp, as an answer to your comment, PreviousPage only works for Server.Transfer and cross page postback.

You'll get null for PreviousPage if :

  • the source page redirects to the destination page.
  • a link at source page forwards the page to destination page.
Canavar
tricky if the previous page is not one that performed the server.transferrequest, i.e. page c.aspx requests b.aspx
maxp