Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome 拒绝帧';https://www.youtube.com/embed/xxxxx 因为它违反了内容安全策略指令_Google Chrome_Firefox_Youtube_Content Security Policy - Fatal编程技术网

Google chrome 拒绝帧';https://www.youtube.com/embed/xxxxx 因为它违反了内容安全策略指令

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,

我试图在我的页面中嵌入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, so 
'default-src' is used as a fallback.
拒绝帧'https://www.youtube.com/embed/?showinfo=0'
因为它违反了以下内容安全策略指令:
“默认src‘self’”。请注意,没有显式设置“frame src”,因此
“默认src”用作回退。
这似乎已经足够清楚了,所以经过一点阅读,我找到了两种设置适当内容安全策略的方法

  • 通过设置响应头(我在web.config文件中这样做):

    
    
  • 页面标题中带有元标记:

    
    
  • 这两种方法都不起作用;Chrome继续在控制台中给出相同的结果(即使我已经按照我认为的消息的意思做了,并设置了请求的内容安全策略)。iframe保持阻塞和空状态

    有很多关于内容安全策略的问题和答案,但我找不到任何与这种情况相结合的答案

    我的站点在https上运行,我的iframe和嵌入式视频如下所示:

    
    
    问题只出现在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"},
                  ...
                  ...
     }