【问题标题】:Iframe pointing at local page is empty and inaccessible指向本地页面的 iframe 为空且无法访问
【发布时间】:2012-03-23 02:28:50
【问题描述】:

这是一个奇怪的功能,直到最近此功能运行良好,并且仍在其他站点上运行。

我正在使用 iframe 来允许用户在页面上启动下载,而无需使用 asp.net 提交实际页面本身:

<iframe id="ifrDownload" name="ifrDownload"  scrolling="no" frameborder="0" marginwidth="0" marginheight="0" style="display: none;" src="Download.aspx"></iframe>  

但是最近在尝试下载时,我在访问 iframe 时收到臭名昭著的“权限被拒绝访问属性‘文档’错误,显然本地文件与父文件在同一个域中,所以我不确定为什么会这样,但我确信这与我在 Firebug 中检查页面时发生的奇怪事情有关。

正常运行的网站在检查时显示以下 iframe 内容:

<iframe id="ifrDownload" scrolling="no" frameborder="0" src="Download.aspx"  style="display: none;" marginheight="0" marginwidth="0">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> </title>
</head>
<body>
<form id="downloadForm" action="Download.aspx" method="post" name="downloadForm">
<div>
<input id="__VIEWSTATE" type="hidden" value="/wEPDwULLTExNjE3Nzc3MzlkZMnbcG6xJn5Jp/GA7fqNd/QyKuTC" name="__VIEWSTATE">
</div>
<div>
<input id="__EVENTVALIDATION" type="hidden" value="/wEWBgLTi7KCAQLnqqEBAuXC+6cLAoPKgZYKAvWdu+YGApj5qL4FFEFbauoxzxy+93iYHGZSO7dPLso=" name="__EVENTVALIDATION">
</div>

<div>
<input id="downloadButton" type="submit" style="display: none;" value="Confirm Download" name="downloadButton">
<input id="attachmentIdField" type="hidden" name="attachmentIdField">
<input id="tableFieldId" type="hidden" name="tableFieldId">
<input id="filenameField" type="hidden" name="filenameField">
<input id="whichField" type="hidden" name="whichField">
</div>

</form>
</body>
</html>
</iframe>

但非工作站点只是显示:

<iframe id="ifrDownload" scrolling="no" frameborder="0" src="Download.aspx" style="display: none;" marginheight="0" marginwidth="0" name="ifrDownload">
<html>
<head></head>
<body></body>
</html>
</iframe>

两个站点的 Download.aspx 文件几乎相同,并且与两个站点的父页面位于同一目录中,我只能认为我无意中将一些代码放在了破坏 iframe 工作方式的地方。

有什么建议吗?我已经对 HTML 进行了 Linted,一切看起来都很好。

【问题讨论】:

    标签: asp.net html iframe


    【解决方案1】:

    好的,经过大量搜索;我在 Global.asax 文件中找到了以下内容:

    void Application_BeginRequest(object sender, EventArgs e) {
        HttpContext.Current.Response.AddHeader("X-Frame-Options", "DENY");
    }
    

    这禁用了所有跨框架选项,有效地禁用了所有链接到 aspx 页面的 iframe,但不是 html 页面。

    删除这段代码,显然是为了停止跨站点脚本,解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-20
      • 2017-05-04
      • 1970-01-01
      • 2021-09-03
      • 2022-01-23
      • 2012-03-03
      • 1970-01-01
      相关资源
      最近更新 更多