且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ASP.NET中跨多个子域共享会话?

更新时间:2023-11-27 18:11:04

你标记了这个使用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.