FosterZ
FosterZ

Reputation: 3911

How to grab the parent url from an iFrame using c#

My scenario is I have a page name UserMain.aspx and in this page I have 2 sections (ie2 IFrames). Now from one of the IFrame pages I want to get parentUrl (ie www.xyz/UserMain.aspx). I have tried the Request.url but it's giving the url of IFrame, how to get the parentUrl?

Both IFrame and parent pages are on same domain.

Upvotes: 6

Views: 23322

Answers (4)

user3334463
user3334463

Reputation: 81

string UrlBrowser= Request.UrlReferrer.OriginalString;

Upvotes: 1

Joachim Prinsloo
Joachim Prinsloo

Reputation: 628

You could try using the following. I tried it in one of my solutions but it was not quite what I needed. Maybe it will help you

Request.UrlReferrer.OriginalString.ToString();

Upvotes: 13

Sachin Shanbhag
Sachin Shanbhag

Reputation: 55489

you can do this through client-side script using window.parent.location.href. This works in case you have an iframe at first level inside a loaded page. If you have more levels of hierarchy, like iframe within iframe ... then you can use window.top.location.href.

window.top always gets you to the topmost parent window.

Upvotes: 0

Guffa
Guffa

Reputation: 700342

The different windows and iframes only exist in the browser, the server code has no means to navigate between them.

In clientscript you can access the URL of the parent window, given of course that the page and iframe is from the same domain:

var parentUrl = window.parent.location.href;

Upvotes: 8

Related Questions