服务器端检测页面显示在 IFrame 中 [英] Server-side detection that a page is shown inside an IFrame

查看:18
本文介绍了服务器端检测页面显示在 IFrame 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以确定 - 服务器端 - 页面是否已在 IFrame 中加载?

当我的应用程序中发生某些错误时,用户会被重定向到 Default.aspx 并显示一条错误消息.该错误消息的文本由异常处理代码在会话中设置.错误消息一旦显示就会从会话中清除.

但是,我的应用程序的一部分必须使用 IFrame(它正在执行 3D 安全卡支付检查,要求使用 IFrame 以显示卡提供商的身份验证用户界面).如果在此过程中发生错误,我的重定向将在 IFrame 内生效.我正在使用 JavaScript 来检测并正确重新加载 Default.aspx,但这意味着我快速连续获得两个 Page_Loads,并且错误消息仅显示在第一个上一个(然后清除).

解决方案

您可以在客户端进行:如何识别网页是在 iframe 内加载还是直接加载到浏览器窗口中?>

我发现的解决方法是将一些标识符放入 iframe 内打开的 url 的查询字符串中.

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).

解决方案

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.

这篇关于服务器端检测页面显示在 IFrame 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆