如何在 ASP.NET 中跨多个子域共享会话? [英] How can I share a session across multiple subdomains in ASP.NET?

查看:33
本文介绍了如何在 ASP.NET 中跨多个子域共享会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,在使用该应用程序的过程中,用户可能会点击来自

I have an application where, in the course of using the application, a user might click from

virginia.usa.com

newyork.usa.com

因为我不想每次用户从一个子域跨到另一个子域时都创建一个新会话,那么跨多个子域共享会话信息的好方法是什么?

Since I'd rather not create a new session each time a user crosses from one subdomain to another, what's a good way to share session info across multiple subdomains?

推荐答案

你用 ASP.NET 和 IIS 标记了这个,所以我假设这是你的环境.确保你的 web.config 中有这个:

You tagged this with ASP.NET and IIS, so I will assume that is your environment. Make sure you have this in your web.config:

<httpCookies domain=".usa.com"/>

如果您的 2 个子域映射到同一个应用程序,那么您就完成了.但是,如果它们是不同的应用程序,您将需要做一些额外的工作,例如使用基于 SQL Server 的会话存储(并破解存储过程以确保所有应用程序共享相同的会话数据)或使用 HttpModule 来拦截应用程序名称,因为即使使用共享 cookie 和相同的机器密钥,2 个应用程序仍将使用 2 个不同的存储来存储它们的会话数据.

If your 2 subdomains map to the same application, then you are done. However, if they are different applications you will need to do some additional work, like using a SQL Server based Session storage (and hacking the stored procedures to make sure all applications share the same session data) or with an HttpModule to intercept the application name, since even with shared cookies and the same machine key, 2 applications will still use 2 different stores for their session data.

这篇关于如何在 ASP.NET 中跨多个子域共享会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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