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

查看:156
本文介绍了如何在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天全站免登陆