【问题标题】:Asp.Net site not showing in iFrameAsp.Net 网站未在 iFrame 中显示
【发布时间】:2024-01-31 04:20:01
【问题描述】:

我想在 iframe 中显示一个外部网站。但我收到此错误:“此内容未显示在框架中”。

 <div id="frameDiv" style="height: 900px;">
<iframe id="leftFrame" src="<%=leftLink%>" width="100%" height="100%" name="leftFrame"></iframe>
 </div>

我也用它作为元标记:

<meta http-equiv="X-Frame-Options" content="SAMEORIGIN" />

谢谢。

【问题讨论】:

  • 有一个 IE 安全设​​置,因为您正在加载外部网站,IE 可能会阻止此设置。工具 --> Internet 选项 --> 安全 --> Internet 区域 --> 自定义级别 --> 其他 --> 在 iframe 中启动程序和文件。使用其他浏览器阅读警告文本 - 发布者 (google) 不允许在 iframe 或框架中托管他们的网站。谷歌通过添加现代浏览器将 - 并且应该 - 遵守的 http 标头“X-FRAME-OPTIONS:DENY”来做到这一点。 developer.mozilla.org/en/The_X-FRAME-OPTIONS_response_header
  • 所以我不能在 Chrome 中使用 iframe?
  • 您在 iFrame 中显示的网站,是您拥有的网站,还是属于公共领域的网站?
  • 这是一个内部使用但在另一个域中的站点。

标签: c# asp.net iframe


【解决方案1】:

试试这个

<iframe name="myIframe" id="myIframe" width="400px" height="400px" runat =server></iframe>

在母版页的代码隐藏中公开此 iframe:

public HtmlControl iframe
{
get
{
return this.myIframe;
}
}

将内容页的 MasterType 指令添加到强类型母版页。

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits=_Default" Title="Untitled Page" %>

<%@ MasterType VirtualPath="~/MasterPage.master" %>

在后面的代码中

protected void Page_Load(object sender, EventArgs e)
{
this.Master.iframe.Attributes.Add("src", "some.aspx");
}

【讨论】:

  • 实际上你遇到什么错误可以粘贴屏幕截图或一些参考
【解决方案2】:

我已经尝试过这个解决方案,它对我的​​问题很有用:

  • 打开 Internet Explorer 并选择“工具 > Internet 选项”。

    选择“隐私”选项卡并选择“高级”按钮。

    “高级隐私设置”窗口将打开。

    勾选“覆盖自动cookie处理”按钮和“确定”回到 Internet Explorer。

现在试试你的问题网站。

【讨论】:

  • 没有代码解决方案?用户需要在所有浏览器上工作,而无需进行此设置。
最近更新 更多