负载用X帧选项否认:" HTTP://test.test.net/Feedback/Create的appid = TestApp"使用MVC5不允许跨域框架 [英] Load denied by X-Frame-Options: "http://test.test.net/Feedback/Create?appId=TestApp" does not permit cross-origin framing using MVC5

查看:508
本文介绍了负载用X帧选项否认:" HTTP://test.test.net/Feedback/Create的appid = TestApp"使用MVC5不允许跨域框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作是托管的我公司的网络上,并从网络中唯一访问的网站上,所以我有跨域请求无关。

不管怎么说,这个特殊的网站我的工作,我添加了导航栏提供反馈链接。这种提供反馈链接打开一个jQuery模态对话框,并且该对话框里面的 IFRAME ,从他们的服务器是一个比这个特定的网站托管在不同的URL负载,因此错误我得到。

MVC4工作正常,没有问题就是这样,只有当我升级到MVC5。有一个关于MVC5不同的东西,美元,被加载到帧p $ pvents内容。

我读过有关设置X框选项ALLOWFROM - 但这是否意味着我需要设置在加载应用程序的URL IFRAME ,或调用应用程序(即在导航栏这个链接的网站)?我要补充的是这个问题只出现了,当我升级了的应该被装载在 IFRAME 从MVC4 /的WebAPI到MVC5 /的WebAPI版本2.我的应用程序这种使用MVC的previous版本没有问题。我怎样才能解决这个问题?

萤火虫的放大版本:

下面是在包含code为提供反馈的应用我的客户端code:

  $(文件)。就绪(函数(){
            $('身体')追加(&LT; D​​IV ID ='对话框的模式'&GT;&LT; IFRAME宽度='900'高度='420' src='http://blah.blah.net/ApplicationName/AppFeedback/Create?appId=TestApp'></iframe></div>\");
            $(#对话框的模式)。对话框({
                纽扣: {
                    关闭:功能(){
                        $(本).dialog(亲密);
                    }
                },
                标题:提供反馈意见!
                的AutoOpen:假的,
                身高:560
                宽度:940,
                模式:真实,
                覆盖:{
                    的backgroundColor:#000000,
                    不透明度:0.75
                },
                可调整大小:真实,
                打开:功能(){
                    $('。UI小部件的覆盖')。绑定(点击,函数(){
                        $('#对话框的模式)对话框(亲密)。
                    })
                }
            });            $(a.feedback)。生活(点击,函数(事件){
                。事件preventDefault();
                $(#对话框的模式)对话框(开放)。
            });


解决方案

把这个在的Global.asax 为我工作:

 保护无效Application_ preSendRequestHeaders(对象发件人,EventArgs的发送)
{
    HttpContext.Current.Response.Headers.Remove(X帧选项);
}

显然有就是它在MVC4工作MVC4和MVC5,之间的差,但不是在MVC5,这是我使用什么

I'm working on a website that's hosted on my company network and only accessible from within the network, so I have no concern with cross-domain requests.

Anyways, this particular website I'm working on I added a "Provide Feedback" link in the navigation bar. This "Provide Feedback" link opens a jQuery modal dialog, and inside this dialog is an iframe that loads from an URL whose server is different than the one this particular website is hosted on, hence the error I'm getting.

MVC4 worked fine, no problems like this, it's only when I upgraded to MVC5. There's something different about MVC5 that prevents content from being loaded into a frame.

I've read about setting the X-Frame options to "ALLOWFROM" - but does this mean I need to set this on the app URL loaded in the iframe, or the calling application (the website that has this link in the nav bar)? I'll also add that this problem only showed up when I upgraded the application that's supposed to be loading in the iframe from MVC4/WebAPI to MVC5/WebAPI version 2. I had no issues with this using the previous version of MVC. How can I resolve this issue?

Larger version of Firebug:

Here's my client-side code in the app that contains the code for "Provide Feedback":

$(document).ready(function () {
            $('body').append("<div id='dialog-modal'><iframe width='900' height='420' src='http://blah.blah.net/ApplicationName/AppFeedback/Create?appId=TestApp'></iframe></div>");
            $("#dialog-modal").dialog({
                buttons: {
                    "Close": function () {
                        $(this).dialog("close");
                    }
                },
                title: "Provide Feedback!",
                autoOpen: false,
                height: 560,
                width: 940,
                modal: true,
                overlay: {
                    backgroundColor: "#000000",
                    opacity: 0.75
                },
                resizable: true,
                open: function () {
                    $('.ui-widget-overlay').bind('click', function () {
                        $('#dialog-modal').dialog('close');
                    })
                }
            });

            $("a.feedback").live("click", function (event) {
                event.preventDefault();
                $("#dialog-modal").dialog("open");
            });

解决方案

Putting this in Global.asax worked for me:

protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
    HttpContext.Current.Response.Headers.Remove("X-Frame-Options");
}

Apparently there's a difference between MVC4 and MVC5, where it worked in MVC4, but not in MVC5, which is what I'm using.

这篇关于负载用X帧选项否认:&QUOT; HTTP://test.test.net/Feedback/Create的appid = TestApp&QUOT;使用MVC5不允许跨域框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆