有哪些选项可用于跨子域共享数据?
我有 www.example.com
和 store.example.com
。 (是的,它们是同一父域的子域)
store.example.com
位于 ASP.NET 1.1
www.example.com
位于 ASP.NET 3.5
我想要了解哪些选项可用于在两个站点之间共享“会话”数据。 我需要某种共享登录以及跟踪用户活动的能力,无论他们从哪个网站开始。
显然,当从一个站点转换到另一个站点时,我可以发送 GUID。 显然
我还相信我可以设置一个可以跨子域共享的 cookie。 我从未尝试过这个,但这很可能是我会做的。 我还不清楚这是否是真正的“会话”cookie,或者我只是设置了一个较低的到期日期?
这些是我最好的选择还是还有其他选择?
I have www.example.com
and also store.example.com
.
(Yes they are subdomains of the same parent domain)
store.example.com
is on ASP.NET 1.1
www.example.com
is on ASP.NET 3.5
I want to know what options are available for sharing 'session' data between the two sites. I need some kind of shared login and also the abiltity to track user activity no matter which site they started on.
Obvously I could send a GUID when transitioning from one site to the other.
I also believe I can set a cookie which can be shared across subdomains. I've never tried this but it is most likely what I will do. I'm not yet clear if this is a true 'session' cookie or if I just set a low expiration date?
Are these my best options or is there somethin else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想在不同应用程序之间共享会话,则需要执行一些操作。
首先,您需要在 SQL 模式下运行会话状态。
此时,我发现 SQL 会话状态使用计算机密钥和您的 _appDomainAppId 来为您的应用程序生成一个密钥来访问它自己的会话数据。 因此,我们需要在所有应用程序之间保持这些相同。
在应用程序的网络配置中,您需要使用相同的机器密钥。 这可以是 system.web 标签内的任何位置 EG:
添加 appSetting“ApplicationName”并为其命名(两个应用程序必须相同)
然后,您需要创建一个共享会话模块,该模块将更改 _appDomainAppId。 下面这个是我用的。
在 Web 配置中,您需要添加此模块:
最后要做的事情是允许会话 cookie 在域之间传递...就像这样
这应该可以解决问题。
If you want to share sessions between different apps there are a few things you need to do.
First you'll need to run the session state in SQL mode.
At this point I found out that the SQL session state takes the machine key and your _appDomainAppId to generate a key for your app to access it's own session data. So we need to keep these the same between all your apps.
In the web configs of your apps you'll need to use the same machine key. This can be any where inside the system.web tags E.G:
Add an appSetting "ApplicationName" and give it name (this has to be the same for both apps)
You'll then need to create a shared session module which will change the _appDomainAppId. The one below is what I use.
In the web config you'll need to add this module:
Final thing to do is to allow the session cookie to pass between domains...like so
And that should do the trick.
重要的是正确设置 cookie 域。
如果域设置为 .example.com(请注意前导句点),则应将其包含在对 example.com 以及所有子域的请求中。
我假设您有一种在不同子域之间共享数据的方法。
The important thing to do is to set the cookie domain properly.
It the domain is set to .example.com (note the leading period) then it should be included in requests to example.com and also all of the subdomains.
I assume you have a way of sharing the data between your different subdomains.
以下是在 PHP 中的操作方法:
http://php.dtbaker.com。 au/post/keeping_cookies_across_multiple_sub_domains.html
Here is how you would do it in PHP:
http://php.dtbaker.com.au/post/keeping_cookies_across_multiple_sub_domains.html