如何在单个asp.net网站上的多个域之间共享会话?
我想在域之间共享会话 cookie。
我有多个域: -
1. mydomain.com
2. mydomain.fr
3. mydomain.de
4. mydomain.da
...and many other language based
现在,我在服务器上部署了一个网站。 我想在单个网站上的不同域之间共享会话。我如何实现这一目标?
我在网络上发现
但它适用于子域(例如 test.mydomain.com)。 com
和 secure.mydomain.com
),但不适用于不同的域。
我还尝试了
但到了这个会话就停止工作了。
有人可以帮我吗?
I want to share session cookie among domains.
I have more than one domain: -
1. mydomain.com
2. mydomain.fr
3. mydomain.de
4. mydomain.da
...and many other language based
Now, I have single website deployed on a server. I want to share session among the different domains on the single website. How do I achieve this?
I found on web <httpCookies domain=".mydomain.com" />
but it work with sub domains (like test.mydomain.com
and secure.mydomain.com
) but not for the different domains.
I also tried <httpCookies domain=".mydomain." />
but by this session stopped working.
Could anyone help me please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您无法在具有不同顶级域名名称的域上共享 Cookie。
这仅适用于子域。
You can't share cookies on domains that have different top level domain name.
This is only possible to do with subdomains.
正如 Oded 所说,您不能在不同的顶级域之间共享 cookie。因此,您可能需要研究一种不同的持久会话方法。
按照 danyolgiax 的建议交换会话状态提供程序并不能解决您的问题,因为会话识别仍在使用 cookie 进行。因此,您需要研究一种方法,例如无 cookie 会话:
Cookieles 会话
然后您可以选择将数据存储在服务器上的数据库或 InProc 会话中。一旦您消除了对 cookie 的依赖。
编辑
此外,如果您使用非身份验证 cookie 的某些客户端活动绝对需要 cookie 存在,您将根据这些服务器/会话存储的值从每个不同的域写入它们。因此,切换域的用户最终会得到您的
每个域的 cookie。
As Oded states you cannot share cookies across different top level domains. Therefore you may need to look into a different method of persisting sessions.
Swapping the Session State provider as danyolgiax proposes will not solve your issue as the session identification is still happening with cookies. Therefore you need to look into an approach such as cookieless sessions:
Cookieles sessions
Then you may choose to store the data in a Database or InProc session on server. Once you've removed the dependency on cookies.
Edit
Additionally then, if you some clientside activity using a non-auth cookie that absolutely requires the cookies to be present you would write them from each different domain based on these server/session stored values. So a user switching domains eventually gets your
cookie for each domain.
您不能直接在不同域之间共享 cookie。但有一种方法可以在某些情况下使其成为可能。您可以在 JS 中发出 JSONP 请求或加载 iframe。如果您使用 iframe,请使用表单进行 http POST 调用。表单标记将您的另一个域名作为操作,将 iframe 名称作为目标。表单将加载一个 iram,并且您的不同域的 cookie 将进入您的浏览器。
代码:
You cannot share a cookie between different domain directly. But there is one way to make it possible at some context. You can make JSONP request or loading an iframe in your JS. if you use iframe make a http POST call using form. Form tag has your another domain name as action and iframe name as a target. What form will do is it will load an ifram and the cookie of your different domain will come in your browser.
Code:
如果您使用 SQL Server,我认为您可以将其用作会话状态提供程序。
在 web.config 中:
这里有一些文档:
http://msdn.microsoft.com/ en-us/library/ms178581.aspx
If you are using SQL Server, I think you can use it as session state provider.
in web.config:
Here some doc:
http://msdn.microsoft.com/en-us/library/ms178581.aspx