3

I would like to put a Back button in my XBAP which takes the user back to the page they launched the XBAP from, however I am not sure how to get the HTTP_REFERER from within the application.

Does anyone know where it exists?

Rachel
  • 130,264
  • 66
  • 304
  • 490
  • Check out Navigation. On MSDN I saw an example of a called page retrieving a parameter from a calling page. The called page has to have a URI to navigate back so it must capture that. I suspect the format of the URI will let you derive the URL. I was not able to test this so I did not post it as an answer. – paparazzo Aug 15 '11 at 15:17
  • @BalamBalam Thanks, but I believe Navigation tracks history for the life of the XBAP only, so it will not contain the caller's URL. – Rachel Aug 15 '11 at 18:42

2 Answers2

1
var h = BrowserInteropHelper.HostScript;
if (h != null)
{
    string s1 = h.location.href;
    if (!s1.StartsWith(sa1))
    {
        MessageBox.Show("Visit the original website at " + sa1 + " or disable referer control");
    }
}
Petroff
  • 21
  • 2
0

If your XBAP is hosted in a frame in the browser, you can go back to the previous page by using interop.

var hostScript = BrowserInteropHelper.HostScript;
if (hostScript != null)
    hostScript.History.Back();

You cannot, however, retrieve the url of the previous page.

Morten Cools
  • 111
  • 4
  • If the user has been navigating around in the XBAP for a while, will the Back button take them to the page they came in at, or their last page within the XBAP? – Rachel Aug 23 '11 at 12:30
  • Actually that isn't working for me. I believe `hostScript` is always null. – Rachel Aug 23 '11 at 12:31
  • Since you are communicating with the browser, it will go back to the previous page in the browser history. You will have to host the xbap in a frame for this to work. – Morten Cools Aug 23 '11 at 16:29
  • The XBAP is deployed in an embedded web browser that is part of our software application, not an actual Browser. Perhaps that's why its not working. – Rachel Aug 23 '11 at 16:41