使用 SQL Server 在 2 个 ASP.NET 应用程序之间共享会话状态

发布于 2024-08-24 16:43:07 字数 925 浏览 9 评论 0原文

我正在开发一个网站,该网站需要在同一域上的 cms 应用程序和在线商店应用程序之间共享会话,例如。

mydomain.com

store.mydomain.com

已经取得了一些进展,它适用于我的本地构建

localhost/cms

localhost/store

基本上我已经完成了本文中建议的操作

http://blogs.msdn.com/toddca/archive/2007/01/25/sharing-asp-net -session-state-across-applications.aspx

并破解 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

http://blogs.msdn.com/toddca/archive/2007/01/25/sharing-asp-net-session-state-across-applications.aspx

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等你爱我 2024-08-31 16:43:07

我们遇到的问题似乎是两个应用程序上的会话 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.

江城子 2024-08-31 16:43:07

使用会话 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文