拒绝在框架中显示,因为它将'X-Frame-Options'设置为'SAMEORIGIN'

Ali*_*mer 252 asp.net-web-api angularjs google-oauth

我正在开发一个应该响应的网站,以便人们可以通过手机访问它.该网站有一些安全的部分,可以使用谷歌,Facebook,...等登录(OAuth).

服务器后端是使用ASP.Net Web API 2开发的,前端主要是带有Razor的AngularJS.

对于身份验证部分,一切都在包括Android在内的所有浏览器中正常运行,但Google身份验证在iPhone上无效,它给了我这个错误消息

Refused to display 'https://accounts.google.com/o/openid2/auth
?openid.ns=http://specs.openid.ne…tp://axschema.org/namePerson
/last&openid.ax.required=email,name,first,last'
in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
Run Code Online (Sandbox Code Playgroud)

现在到目前为止我担心我的HTML文件中不使用任何iframe.

我用Google搜索,但没有回答让我解决问题.

小智 164

我发现了一个更好的解决方案,也许它可以帮助别人替代"watch?v=""v/",它会工作

var url = url.replace("watch?v=", "v/");
Run Code Online (Sandbox Code Playgroud)

  • 您也可以将其更改为使用"embed /"而不是"v /",以便完整的URL变为:`<iframe width ='1080'height ='760'src ="https://www.youtube.com/ embed/dQw4w9WgXcQ"frameborder ="0"allowfullscreen></iframe> </ iframe>` (46认同)
  • 我建议将此答案更改为“embed/”,因为“v/”不再起作用 (2认同)

Ali*_*mer 84

在这篇SO帖子的帮助下,花了更多的时间在这之后确定了

克服"X-Frame-Options禁止显示"

我设法通过&output=embed在发布到Google网址之前添加到网址末尾来解决问题:

var url = data.url + "&output=embed";
window.location.replace(url);
Run Code Online (Sandbox Code Playgroud)

  • 实际上,正如我在原始帖子中所述,这是针对 OAUTH 的。在 OAUTH 2.0 中仍然如此。不过,Google 已更改其设置以使用该服务,因此现在您必须专门更改一些属性才能使用 OAUTH 2.0,OWIN 3.0 中间件就是这种情况。如果您收到“access_denied”错误消息,请参阅此链接。http://blogs.msdn.com/b/webdev/archive/2014/07/02/changes-to-google-oauth-2-0-and-updates-in-google-middleware-for-3-0- 0-rc-release.aspx (2认同)
  • 也不适用于应用程序 Web 视图中的 Google 日历 iframe。 (2认同)
  • 如果我想要在 iframe 中的移动应用程序中显示我的其他网站,该怎么办 (2认同)

Bog*_*aru 38

尝试使用

https://www.youtube.com/embed/YOUR_VIDEO_CODE

您可以在"嵌入代码"部分找到所有嵌入代码,看起来像这样

<iframe width="560" height="315"  src="https://www.youtube.com/embed/YOUR_VIDEO_CODE" frameborder="0" allowfullscreen></iframe>
Run Code Online (Sandbox Code Playgroud)


Ibt*_*tif 31

在这种情况下,他们已将标头设置为SAMEORIGIN,这意味着他们不允许在其域外的iframe中加载资源.所以这个iframe无法显示跨域

在此输入图像描述

为此,您需要匹配apache中的位置或您正在使用的任何其他服务

如果您正在使用apache然后在httpd.conf文件中.

  <LocationMatch "/your_relative_path">
      ProxyPass absolute_path_of_your_application/your_relative_path
      ProxyPassReverse absolute_path_of_your_application/your_relative_path
   </LocationMatch>
Run Code Online (Sandbox Code Playgroud)

  • 什么是“ your_relative_path”? (2认同)
  • 什么是your_relative_path? (2认同)

Sha*_*med 19

如果您使用iframe进行vimeo,请更改以下网址:

https://vimeo.com/63534746

至:

http://player.vimeo.com/video/63534746

这个对我有用.


Irf*_*mad 11

要将youtube视频嵌入到angularjs页面中,您只需对视频使用以下过滤器即可

app.filter('scrurl', function($sce) {
    return function(text) {
        text = text.replace("watch?v=", "embed/");
        return $sce.trustAsResourceUrl(text);
    };
});
Run Code Online (Sandbox Code Playgroud)
<iframe class="ytplayer" type="text/html" width="100%" height="360" src="{{youtube_url | scrurl}}" frameborder="0"></iframe>
Run Code Online (Sandbox Code Playgroud)


par*_*ent 7

对我来说,解决方法是进入console.developer.google.com并将应用程序域添加到OAuth\xc2\xa02凭据的“JavaScript Origins”部分。

\n


小智 6

我做了以下更改,对我来说效果很好。

只需添加属性 <iframe src="URL" target="_parent" />

_parent:这将在同一窗口中打开嵌入式页面。

_blank:在其他标签中