如何限制将角度应用程序加载到iframe中

问题描述

我正在尝试限制将角度应用程序加载到iframe中,但无法做到这一点。

我有angular个应用独立于API运行。使用.net core 2.1实现API,使用angular 7实现UI客户端。

我在api middleware中尝试了以下不同的选项,但是在我的情况下没有一个起作用:

#1

    app.Use(async (context,next) =>
    {
        context.Response.Headers.Add("Content-Security-Policy","frame-ancestors 'none'; " +
            "script-src 'self'; " +
            "style-src 'self'; " +
            "img-src 'self'");
        await next();
    });

#2

    app.Use(async (context,next) =>
    {
        context.Response.Headers.Add("X-Frame-Options","DENY");
        await next();
    });

我已经超越了response header中的附加值,但仍然能够在其他应用程序的iframe中加载应用程序。

angular/API边,我这里缺少什么吗?

添加了更多信息

我们使用IIS托管角度应用程序。还尝试了以下在角度应用程序的web.config中进行设置:

<httpProtocol>
    <customHeaders>
      <add name="X-Frame-Options" value="DENY" />
    </customHeaders>
</httpProtocol>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)