从在子域上运行的应用程序访问父域Cookie [英] Access parent domain cookies from an application running on a subdomain

查看:1229
本文介绍了从在子域上运行的应用程序访问父域Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个cookie设置在父域的路径(我不能控制)。但我有一个应用程序运行在其中一个子域(我可以访问这个)。如何访问针对父域设置的Cookie?

I have a cookie set in the path of the parent domain ( which I have no control over). But I have an application running in one of the subdomains (I have access to this). How can I access the cookies set against the parent domain?

例如,假设我有Cookie:

For instance, say I have the cookies:

Name     Value     Domain (not https)
ABC      1         .example.com
XYZ      0         foo.bar.example.com

应用程式正在 foo.bar.example.com 上执行, .example.com
这是一个Java应用程序。我尝试调试,但我只能看到设置为子域,而不是主域的cookie。

The app is running on foo.bar.example.com and the cookie is set at .example.com It's a Java application. I tried to debug but I can only see the cookies set for the subdomain, not the primary domain.

这是源

Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            for (Cookie cookie : cookies) {
            //Here I only see cookies set for the sub domain but not the parent domain. The cookies collection has no parent domain cookies.

            }
        }

http://stackoverflow.com/a/1039111/1324816\">这个stackoverflow回答可能是浏览器没有发送父域cookie到应用程序?

Also according to this stackoverflow answer maybe the browser is not sending the parent domain cookies to the app?

我觉得我在这里缺少一些基本的东西。任何建议?

I feel like I'm missing something elementary here. Any suggestions?

推荐答案

我的例子中的问题是一个外部代理服务器(我的情况下SSO服务器)过滤Cookie。所以这是一个环境问题。我确信父域cookie在正常环境中可用。

The problem in my case was an external Proxy server (SSO server in my case) was filtering the cookies. So it was an environmental problem. I'm sure that parent domain cookies are available in normal environments.

这篇关于从在子域上运行的应用程序访问父域Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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