简体   繁体   English

服务器端检测页面显示在IFrame中

[英]Server-side detection that a page is shown inside an IFrame

Is it possible to determine - server-side - whether a page has been loaded within an IFrame ? 是否可以确定 - 服务器端 - 是否已在IFrame加载页面?

When certain errors happen in my application the user gets redirected to Default.aspx and an error message is shown. 当我的应用程序中发生某些错误时,用户将被重定向到Default.aspx并显示错误消息。 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). 但是,我的部分应用程序必须使用IFrame (它正在执行3D安全卡支付检查,该检查要求IFrame以显示卡提供商的身份验证UI)。 If an error takes place during this process my redirect takes effect within the IFrame . 如果在此过程中发生错误,我的重定向将在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). 我使用JavaScript来检测它并正确地重新加载Default.aspx ,但这意味着我快速连续获得两个Page_Loads ,并且错误消息仅显示在第一个(然后清除)。

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? 您可以在客户端执行此操作: 如何识别是在iframe中加载网页还是直接加载到浏览器窗口中?

The workaround i found is put some identifier into querystring of a url opened inside iframe. 我找到的解决方法是将一些标识符放入iframe中打开的URL的查询字符串中。

This is impossible because client can open iframe with javascript disabled. 这是不可能的,因为客户端可以在禁用javascript的情况下打开iframe。 http://caniuse.com/#feat=iframe-sandbox http://caniuse.com/#feat=iframe-sandbox

我不认为您可以检测到某种类型的Page.IsInIFrame()类型的功能,但您可以考虑为那些在IFrame中加载的页面设置不同的基类,而不是那些您可以知道错误来自IFrame页面的请求,该请求可能在某种程度上有所帮助。

There's no way from the server-side. 服务器端没办法。 The only way is via javascript. 唯一的方法是通过JavaScript。 When you do the redirect, can you pass the error message or code via a querystring? 当您执行重定向时,是否可以通过查询字符串传递错误消息或代码?

Won't it work to redirect using Javascript with window.location? 使用带有window.location的Javascript重定向是不行的? Forcing a full page redirect? 强制整页重定向?

simply, check the url of current page.. if it's the same with the IFrame page then redirect to Default.aspx or whatever. 简单地说,检查当前页面的URL ..如果它与IFrame页面相同,则重定向到Default.aspx或其他。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM