10

Is it possible to determine - server-side - whether a page has been loaded within an IFrame?

When certain errors happen in my application the user gets redirected to Default.aspx and an error message is shown. The text of that error message gets set in session by exception handling code. The error message gets cleared from session once it has been shown.

However, part of my application has to use an IFrame (it's doing a 3D Secure card payment check, which mandates an IFrame in order to display the card provider's authentication UI). If an error takes place during this process my redirect takes effect within the IFrame. I am using JavaScript to detect this and reload Default.aspx correctly, but this means that I get two Page_Loads in rapid succession, and the error message only gets shown on the first one (and then cleared).

Richard Ev
  • 52,939
  • 59
  • 191
  • 278
  • 1
    Mozilla Developer Network. I actually think I just opened up a whole can of worms with this and probably shouldn't have added my message here until I learned myself what's going on, sorry. (see http://stackoverflow.com/questions/15344187/how-does-it-appear-that-mdn-can-detect-a-request-from-an-iframe-on-the-server-si) – JayC Mar 11 '13 at 17:00

6 Answers6

3

You can do it in client side: How to identify if a webpage is being loaded inside an iframe or directly into the browser window?

The workaround i found is put some identifier into querystring of a url opened inside iframe.

Community
  • 1
  • 1
Afonso França
  • 663
  • 1
  • 4
  • 14
0

This is impossible because client can open iframe with javascript disabled. http://caniuse.com/#feat=iframe-sandbox

puchu
  • 3,294
  • 6
  • 38
  • 62
0

I don't think you can detect in the sense of having some sort of Page.IsInIFrame() kind of functionality, but you could consider having different base classes for those pages that are loaded in an IFrame and those that aren't so that you can know the error is from a request that was for an IFrame page that may help to some extent.

JB King
  • 11,860
  • 4
  • 38
  • 49
0

There's no way from the server-side. The only way is via javascript. When you do the redirect, can you pass the error message or code via a querystring?

Keltex
  • 26,220
  • 11
  • 79
  • 111
0

Won't it work to redirect using Javascript with window.location? Forcing a full page redirect?

cerhart
  • 381
  • 3
  • 17
-3

simply, check the url of current page.. if it's the same with the IFrame page then redirect to Default.aspx or whatever.

Dim urlpath1 As String = HttpContext.Current.Request.Url.AbsoluteUri
If Right(urlpath1, 13) = "WebForm1.aspx" Then
       Response.Redirect("~/")
   Else
       Response.Write("It's OK!")
   End If