使用asp.net和状态服务器在两个网站之间共享会话 [英] Share Session between two web sites using asp.net and state server

查看:17
本文介绍了使用asp.net和状态服务器在两个网站之间共享会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 IIS 7.5 下的两台不同机器上托管了两个完全相同的网站.ASP.NET 状态服务正在我的机器上运行,并且两个站点中的 web.config 都使用以下代码更新:

I have two exactly the same web sites hosted in two different machines under IIS 7.5. ASP.NET state service is running on my machine and the web.config is updated in both sites with the following code:

<sessionState mode="StateServer" stateConnectionString="tcpip=192.168.1.77:42424" cookieless="false" timeout="120"/>

在注册表中将允许远程连接设置为 1,以便第二个网站访问状态服务器.

The allow remote connection is set to 1 in registry in order for the second web site to access the state server.

两个网站都有相同的机器密钥:

Both web sites have the same machine key:

<代码><的machineKey的validationKey = 7CB8DF6872FB6B35DECD3A8F55582350FEE1FAB9BE6B930216056C1B5BA69A4C5777B3125A42C4AECB4419D43EC12F168​​FD1BB887469798093C3CAA2427B2B89" decryptionKey = 02FC52E4C71544868EE297826A613C53537DF8FDAF93FA2C64E9A5EF0BA467FB" 验证= SHA1" 解密= AES"/>

此外,两个站点都在 IIS 中配置为具有相同的标识符.

Additionally both sites are configured in IIS to have the same Identifier.

我想要做的是这两个站点共享相同的会话数据,例如能够执行以下操作:

What I want to do is that both these sites share the same session data for example being able to do the following:

// At web site 1: 
Session["key"] = "value"

// At web site 2:
// Read session value from the other web site
string result = Session["key"]

问题是我无法完成这个测试,真的无法理解我做错了什么.

The problem is that I can't manage to accomplish this test and really can't understand what I am doing wrong.

任何可能有帮助的想法?

Any idea that might help?

推荐答案

无论浏览器访问哪个站点,您都需要一种方法来说服浏览器发送相同的 ASP.NET 会话 cookie.

You'll need a way to convince your browser to send the same ASP.NET session cookie regardless of which site it visits.

如果请求中不存在 cookie,则将使用该密钥创建一个新会话.

If the cookie isn't present on the request, then a new session will get created with that key.

我认为您可以通过一些狡猾的 DNS 配置让浏览器保留密钥 - 如果您分配 http://website1.mydomain.com/http://website2.domain.com/您的站点地址,然后将 ASP.NET 会话 cookie 的域设置为domain.com",然后您的浏览器会将其发送到两个站点并共享会话.

I think you can get the browser to retain the key with some sneaky DNS configs - if you assign http://website1.mydomain.com/ and http://website2.domain.com/ to be the addresses of your sites, then set the domain of the ASP.NET session cookie to "domain.com", then your browser will send it to both sites and the session should be shared.

您也可以在 ASP.NET 中使用 cookieless 模式,并从生成的 URL 中获取会话 ID.

You may also be able to use cookieless mode with ASP.NET, and grab the session ID from the generated URLs.

这篇关于使用asp.net和状态服务器在两个网站之间共享会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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