maxp
maxp

Reputation: 25141

Server.Transferrequest() and getting the current URL

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".

Upvotes: 3

Views: 7387

Answers (5)

Sergio
Sergio

Reputation: 8259

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.

Upvotes: 2

Denis
Denis

Reputation: 3747

NameValueCollection headers = new NameValueCollection();
headers["RawUrl"] = HttpContext.Current.Request.RawUrl;
Server.TransferRequest("b.aspx", true, null, headers);

And then use Headers["RawUrl"] in b.aspx.

Upvotes: 1

Dorin
Dorin

Reputation: 2542

Have you tried this method:

public void Transfer(string path, bool preserveForm )

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

I currently got in the same problem, and I found out that Server object has this parameter on transfer method that gives you the posibility to preserve the original request form or not.

Upvotes: 0

Canavar
Canavar

Reputation: 48088

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.

Upvotes: 0

John Boker
John Boker

Reputation: 83699

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

Upvotes: 1

Related Questions