【发布时间】:2021-02-07 05:23:09
【问题描述】:
我正在尝试限制 Angular 应用程序在 iframe 中加载,但无法做到这一点。
我有angular 应用程序独立于API 运行。 API 使用.net core 2.1 实现,UI 客户端使用angular 7。
我在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 来托管 Angular 应用程序。还尝试在 Angular 应用程序的 web.config 中进行以下设置:
<httpProtocol>
<customHeaders>
<add name="X-Frame-Options" value="DENY" />
</customHeaders>
</httpProtocol>
【问题讨论】:
标签: angular angular7 asp.net-core-webapi asp.net-core-2.1