简体   繁体   English

设置CORS IIS7

[英]Set Up CORS IIS7

I have a webforms site and I am trying to make a web request via JQuery to a page on the same site. 我有一个Webforms站点,我正在尝试通过JQuery向同一站点上的页面发出Web请求。 However the page I am trying to access is on HTTPS rather than the HTTP that the page the Jquery is executed from uses. 但是,我尝试访问的页面是在HTTPS上,而不是从Jquery执行的页面使用的HTTP。 I get an error regarding "Access-Control-Allow-Origin" so I looked into it and I now have the following added to my web.config. 我收到有关“ Access-Control-Allow-Origin”的错误,因此我对其进行了调查,现在将以下内容添加到我的web.config中。

<httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
      </customHeaders>
    </httpProtocol>

And this is my JQuery 这是我的JQuery

<script type="text/javascript">
    $( document ).ready(function() {
        $.ajax({
            type: "GET",
            headers: {
                "Access-Control-Allow-Origin": "*"
            },
            url: "https://www.example.com",
            success: function (resp) {
                //register browser as supported
                console.log("supported");
            },
            error:function(e){
                //register browser as unsupported
                console.log(e);
                console.log("unsupported");
            }
        })
    })
</script>

However I now get the following error 但是我现在得到以下错误

XMLHttpRequest cannot load https://www.example.com/ . XMLHttpRequest无法加载https://www.example.com/ Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. 对预检请求的响应未通过访问控制检查:请求的资源上不存在“ Access-Control-Allow-Origin”标头。 Origin ' http://www.example.com ' is therefore not allowed access. 因此,不允许访问来源“ http://www.example.com ”。

What do I need to do to get this to work? 我需要做什么才能使它正常工作?

I have realised what was happening. 我已经意识到发生了什么事。 We have a strange setup where there is a CMS system that is the root site but the rest of the system is its own webforms application. 我们有一个奇怪的设置,其中有一个CMS系统是根站点,而系统的其余部分是它自己的webforms应用程序。 The CMS systems web.config gets called first so that is where the changes needed to be made but I had made them in the main sites web.config. CMS系统的web.config首先被调用,因此需要在此处进行更改,但是我已经在主要站点web.config中进行了更改。

Silly setup.... 愚蠢的设置...

Thanks for the help. 谢谢您的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM