这样做的目的是阻止其他网站在iframe中显示我们网站的内容。
我不能使用X-Frame-Options = SAMEORIGIN,因为网站的网址。主节点为www.xyz.com,子节点为sec.xyz.com。
所以我求助于内容安全策略(...表示其他域等)
<httpProtocol>
<customHeaders>
<add name="Content-Security-Policy" value="default-src 'self' localhost ...; script-src 'unsafe-inline' 'unsafe-eval' *; style-src 'unsafe-inline' *; img-src * data; font-src * data:; frame-ancestors 'self' localhost ...;" />
</customHeaders>
</httpProtocol>FF和Chrome不会在测试页面iframe中显示站点。

现在IE 11在iframe中显示了站点,因为不支持frame-祖先。https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors
我尝试在全局文件中添加头文件X-Content-Security-Policy,但IE11仍然显示该站点。
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("X-Content-Security-Policy", "frame-ancestors 'self' localhost ...");
}

如何使IE 11遵守标头X-Content-Security-Policy
发布于 2019-05-10 03:00:42
IE不支持X-Content-Security-Policy的frame-ancestors。使用X-Frame-Options和ALLOW-FROM定位IE。
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
https://stackoverflow.com/questions/55974092
复制相似问题