首页 > 解决方案 > 在 IFrame 中加载 localhost 站点的问题

问题描述

我有一个要加载到 Iframe 中的 MVC 站点。我已将 X-Frame-Options 添加到 AllowAll。当我尝试加载站点时,我可以在开发人员工具中看到 html 文档,但页面中的 IFrame 是空白的。

我尝试在 localhost 上创建一个具有不同端口号的 Web 应用程序,并且尝试在 Iframe 中加载 MVC 站点,但它没有工作。我试图在同一个 MVC 站点中添加一个 html 并将其自身加载到 html 的 Iframe 中(假设端口问题,但它仍然不会加载)。

在此处输入图像描述

任何帮助将不胜感激。

标签: asp.netiframe

解决方案


我最近遇到了类似的问题。标题X-Frame-Options对我不起作用。我不得不使用Content-Security-Policy标题。在web.config文件中,我将其设置为frame-src https://my-domain.com

<system.webServer>
    <httpProtocol>
        <customHeaders>
            <add name="Content-Security-Policy" value="frame-src {your domain here}" />
        </customHeaders>
    </httpProtocol>
</system.webServer>

推荐阅读