【问题标题】:Refused to display '' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN' [closed]拒绝在框架中显示“”,因为它将“X-Frame-Options”设置为“SAMEORIGIN”[关闭]
【发布时间】:2014-11-14 14:07:48
【问题描述】:

我做了一个 MVC ASP.NET C# 项目,主要是一个表单。

但是,当我 iframe 正确的 url 时,它显示为空白

注意:我没有写任何关于 iframe 的代码

我需要打开一个选项才能使 iframe 成为可能吗?

FirefoxConsole Error message:

Load denied by X-Frame-Options: http://localhost:2053/Persons/Create does not permit cross-origin framing.

 Chrome Error message: 

  Refused to display 'http://localhost:2053/Persons/Create' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'. 

【问题讨论】:

  • 'iframe 正确的 url' - 你能解释一下吗?
  • 你能正常浏览到那个url吗? (即不在 iframe 中),您可以从 iframe 页面发布 代码吗?
  • 对不起,我搞砸了,现在解决我的问题
  • 你已经完全改变了错误信息! gaaa 我放弃了。

标签: c# asp.net-mvc iframe


【解决方案1】:

找到解决方案:将其添加到 global.asax.cs

  protected void Application_PreSendRequestHeaders()
    {
        Response.Headers.Remove("X-Frame-Options");
         Response.AddHeader("X-Frame-Options", "AllowAll");

    }

【讨论】:

  • 我的情况:我在 ASP.NET MVC 5 中创建了一个应用程序,然后尝试在 Sharepoint 站点中的 iframe 上进行渲染,我收到了这篇文章标题中所说的错误,并且得到了您的回答一切正常。我想知道你在哪里找到这个答案?只是为了将来的文档。
  • “AllowAll”值是任何规范的一部分吗?如果这里没有提到:tools.ietf.org/html/rfc7034
猜你喜欢
  • 2013-12-28
  • 2017-05-22
  • 2022-11-29
  • 2016-10-08
  • 2018-02-22
  • 2018-08-05
  • 2020-11-07
相关资源
最近更新 更多