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

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
maxp
  • 24,209
  • 39
  • 123
  • 201

5 Answers5

2

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.

James Skemp
  • 8,018
  • 9
  • 64
  • 107
Sergio
  • 8,125
  • 10
  • 46
  • 77
1

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

John Boker
  • 82,559
  • 17
  • 97
  • 130
1
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.

Denis
  • 3,653
  • 4
  • 30
  • 43
0

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
  • 47,715
  • 17
  • 91
  • 122
  • tricky if the previous page is not one that performed the server.transferrequest, i.e. page c.aspx requests b.aspx – maxp Jul 23 '09 at 14:07
  • PreviousPage is set by `Server.Transfer()`, but **NOT** by `Server.TransferRequest()`. Just verified with tests. The OP was using `Server.TransferRequest()`. – jk7 Jun 09 '23 at 18:39
0

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.

Dorin
  • 2,482
  • 2
  • 22
  • 38