How can I get the referer in an XBAP or ClickOnce Application?
I would like to put a Back
button in my XBAP which takes the 开发者_JS百科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?
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");
}
}
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.
精彩评论