使用 SQL Server 在 2 个 ASP.NET 应用程序之间共享会话状态
我正在开发一个网站,该网站需要在同一域上的 cms 应用程序和在线商店应用程序之间共享会话,例如。
mydomain.com
我
store.mydomain.com
已经取得了一些进展,它适用于我的本地构建
localhost/cms
,
localhost/store
基本上我已经完成了本文中建议的操作
并破解 TempGetAppID 存储过程以返回相同的应用程序 ID (1)。这似乎有效,因为它创建了带有“abv5d2urx1asscfwuzw3wp4500000001”等 id 的会话,这正是我所期望的。
我的问题是,当我将其部署到测试环境时,当我在两个站点之间导航时,它会创建一个新会话。因此,当我在 cms 站点上启动会话时,如果我导航到商店,它会创建一个新会话。这些在 IIS7 中设置为 2 个不同的网站。
在两个站点的 web.config 文件中, 和 元素都是相同的,如下所示(减去敏感信息)
有谁知道为什么这可能行不通?我在两个站点之间共享表单身份验证,效果很好。任何帮助或想法将不胜感激!
非常感谢
戴夫
I'm working on a site that has a requirement to share session between a cms application and an online store application on the same domain eg.
mydomain.com
and
store.mydomain.com
I've made some progress with it and it works on my local build between
localhost/cms
and
localhost/store
Basically I have done what is suggested in this article
and hacked the TempGetAppID Stored Procedure to return the same application id (1). This appears to work as it creates sessions with ids like 'abv5d2urx1asscfwuzw3wp4500000001', which is what I'd expect.
My issue is that when I deploy it to our testing environment, it creates a new session when I navigate between the 2 sites. So when I start a session on the cms site, if I navigate to the store, it creates a new session. These are set up as 2 different websites in IIS7.
In the web.config files for both sites, the and elements are both the same and are as follows (minus sensitive information)
Has anyone got an ideas why this might not be working? I am sharing Forms Authentication across the 2 sites and that works fine. Any help or ideas would be greatly appreciated!
Many thanks
Dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们遇到的问题似乎是两个应用程序上的会话 cookie 域设置不同。这意味着每个应用程序都会生成自己的 sessionId。
我们添加了
到我们的 web.config ,这似乎已经解决了它。感谢您的帮助,希望这对将来的其他人有帮助。
It appears the issue we were having was that the session cookie domain was being being set differently on the 2 applications. This meant that each application generated it's own sessionId.
We added
<httpCookies domain=".ourdomain.co.uk" />
to our web.config and that seems to have solved it. Thanks for hte help, hope this helps someone else in the future.
使用会话 ID 作为键,将所有会话数据保留在 SQL 服务器上。然后使用包含指向
.mydomain.com
的会话 ID 的 cookie,以便它在两个子域上都可用。这篇 15 秒的文章涵盖了该主题,甚至展示了一种在完全不同的环境中共享会话的技术域。
Persist all session data on the SQL-server, using the session-ID as key. Then use a cookie containing the session-ID that points to
.mydomain.com
so it will be available on both sub-domains.This article at 15 seconds covers the subject and even shows a technique to share sessions across completely different domains.