指向本地页面的Iframe为空且不可访问



这是一个奇怪的问题,因为直到最近,这个功能还可以正常工作,并且仍然在不同的网站上工作。

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

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

然而,最近在尝试下载时,我在访问iframe时遇到了臭名昭著的"访问属性'document'的权限被拒绝"错误,显然本地文件与父文件在同一个域上,所以我不确定为什么会发生这种情况,但我确信这与我在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的工作方式。

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

好的,经过多次搜索;我在Global.asax文件中发现了以下内容:

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

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

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

最新更新