11

I'm running an c# .net app in an iframe of an asp page on an older site. Accessing the Asp page's session information is somewhat difficult, so I'd like to make my .net app simply verify that it's being called from an approved page, or else immediately halt.

Is there a way for a page to find out the url of it's parent document?

Andrew Edvalson
  • 7,658
  • 5
  • 26
  • 24

3 Answers3

11
top.location.href

But that will only work if both pages (the iframe and the main page) are being served from the same domain.

Dan
  • 61,568
  • 9
  • 61
  • 78
  • 1
    @Dan Is it possible for this to work across two separate top-level domains? cheers – Lea Hayes Oct 23 '11 at 20:42
  • @Dan is this property available in the code behind before the page is actually rendered? For example, if I want to do something different within Page_Load (or some other event during the GET) - is there a way to inspect this value, and say *not* render the page when the top.location.href is not what I expect it to be? – qxotk Jul 30 '19 at 18:51
2

To get the URL:

Request.UrlReferrer....

To digest the query string:

NameValueCollection qs = HttpUtility.ParseQueryString(Request.UrlReferrer.Query);
Das_Geek
  • 2,775
  • 7
  • 20
  • 26
jumpdart
  • 1,702
  • 16
  • 35
  • does the Request.UrlReferrer always point to the parent of the iframe? Is it not possible that if someone navigated directly to the iframe URL after visiting the previously visiting the parent that this method might show a false positive? – qxotk Jul 30 '19 at 18:48
1
parent.location.href
Raleigh Buckner
  • 8,343
  • 2
  • 31
  • 38