首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >CORS请求与IE11

CORS请求与IE11
EN

Stack Overflow用户
提问于 2018-04-25 08:40:28
回答 2查看 0关注 0票数 0

我有一个来自我的登录页面到应用程序站点的CORS(跨源数据共享)请求,位于另一个URL上。我有一个简单的页面,可以确定用户是否已经登录,如果是,则重定向它们。否则,我会显示一个登录页面。我使用jQuery。

这在safari,chrome,firefox ...以及IE(自然)中都很好用。根据MS,IE 10和更高版本应该使用withCredentials来支持CORS请求

我正在使用jquery-2.0.3.min.js

任何想法,为什么这不适用于IE11?

它看起来好像它是部分工作,因为它现在返回值{“id”:false}。每次都会发生这种情况,这意味着服务器永远不会获得凭据。我也发布我的is_logged_in页面,我使用的代码点火框架。

在IE的安全设置下启用“允许跨域的数据源”后,我不再收到任何错误消息。

代码语言:javascript
复制
$.ajax({
url: 'http://mysite.net/guest/is_logged_in',
type: 'POST',
crossDomain: true,
xhrFields: {
       withCredentials: true
  },

dataType: 'json',
success: function(data) {

    if(data.id) {
        window.location.replace("http://mysite.net");
    }
}
});

代码语言:javascript
复制
public function is_logged_in()
{
    $allowed = array(
        'http://mysite.net',
        'http://www.mysite.net',
        'http://www.mysite.com',
    );

    $url = $_SERVER['HTTP_REFERER'];
    $url = substr($url, 0, strpos($url, '/', 8));
    if(isset($_SERVER['HTTP_ORIGIN']))
    {
        if(in_array($_SERVER['HTTP_ORIGIN'], $allowed))
        {
            $this->output->set_header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
        }
    }
    else
    {
        if(in_array($url, $allowed))
        {
            $this->output->set_header('Access-Control-Allow-Origin: ' . $url);
        }
    }


    $this->output->set_header('Access-Control-Allow-Headers: X-Requested-With');
    $this->output->set_header('Access-Control-Allow-Credentials: true');
    $this->output->set_header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");


    //TODO: Try to detect if this is an ajax request, and disallow it if not.

    $data = new stdClass();
    $this->load->library("ion_auth");
    if($this->ion_auth->logged_in())
    {
        $data->name = $this->ion_auth->user()->row()->first_name;
        $data->id = $this->ion_auth->get_user_id();
    } else {
        $data->id = false;
    }

    $this->output->set_output(json_encode($data));

}
EN

回答 2

Stack Overflow用户

发布于 2018-04-25 16:42:11

将“跨数据源访问数据源”的设置更改为“已启用”会关闭IE中的跨域检查,并且可怕地不安全。相反,需要确保目标第三方资源发送一个有效的P3P策略,表明它不会对用户的隐私造成可怕的影响。

票数 0
EN

Stack Overflow用户

发布于 2018-04-25 18:34:47

发现问题。

我有一个类似的问题(一般使用CORS,而不是特定的GWT)。事实证明,浏览器设置阻止了第三方cookie(IE10> Internet选项>隐私>高级>第三方Cookie>接受)。为了解决这个问题,我选中了“覆盖自动cookie处理”,“接受”(第三方Cookies)和“始终允许会话cookie”

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100008260

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档