Google chrome 拒绝帧';https://www.youtube.com/embed/xxxxx 因为它违反了内容安全策略指令
我试图在我的页面中嵌入youtube视频,但在控制台中看到如下错误:Google chrome 拒绝帧';https://www.youtube.com/embed/xxxxx 因为它违反了内容安全策略指令,google-chrome,firefox,youtube,content-security-policy,Google Chrome,Firefox,Youtube,Content Security Policy,我试图在我的页面中嵌入youtube视频,但在控制台中看到如下错误: Refused to frame 'https://www.youtube.com/embed/<~videoId~>?showinfo=0' because it violates the following Content Security Policy directive: "default-src 'self'". Note that 'frame-src' was not explicitly set,
Refused to frame 'https://www.youtube.com/embed/<~videoId~>?showinfo=0'
because it violates the following Content Security Policy directive:
"default-src 'self'". Note that 'frame-src' was not explicitly set, so
'default-src' is used as a fallback.
拒绝帧'https://www.youtube.com/embed/?showinfo=0'
因为它违反了以下内容安全策略指令:
“默认src‘self’”。请注意,没有显式设置“frame src”,因此
“默认src”用作回退。
这似乎已经足够清楚了,所以经过一点阅读,我找到了两种设置适当内容安全策略的方法
问题只出现在Chrome和FFirefox上;如果没有内容安全策略,Internet Explorer 11也可以
提前感谢您的建议。我自己找到了答案。我试图在Identity Server 3安装的登录页面上嵌入一个视频,这比我想象的要大得多 Chrome网络选项卡包含Identity Server的csp报告,通过快速搜索,Identity Server文档中的答案如下: 在identity server选项中添加CSPTOPTIONS条目修复了entirelt问题,而无需添加任何自定义标题:
var options = new IdentityServerOptions
{
SigningCertificate = Certificate.Load(),
Factory = factory,
RequireSsl = true,
CspOptions = new CspOptions() {FrameSrc = "https://www.youtube.com"},
...
...
}
这是网上的吗?这样我就可以看一看了?错误显示为
“defaultsrc'self'”
,这意味着它看不到您的任何一个值。您是否在网络活动中看到预期的响应标头?你是在一个框架内装帧吗?@oreoshake不是,它目前正在开发中,只在我的本地机器上可用。框架代码与上面列出的一模一样,一直困扰着我,直到我意识到这是一个IdentityServer的东西——我在下面发布了解决方案。
<meta http-equiv="Content-Security-Policy" content="frame-src https://www.youtube.com">
<div id="videoContainer">
<iframe src="https://www.youtube.com/embed/<~videoId~>?showinfo=0"
frameborder="0"
allowfullscreen>
</iframe>
</div>
var options = new IdentityServerOptions
{
SigningCertificate = Certificate.Load(),
Factory = factory,
RequireSsl = true,
CspOptions = new CspOptions() {FrameSrc = "https://www.youtube.com"},
...
...
}