使用State Server在不同的.NET版本之间共享会话状态 [英] Sharing Session State between different .NET Versions using State Server

查看:252
本文介绍了使用State Server在不同的.NET版本之间共享会话状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 我们使用.NET 3.5在IIS 6(Win2003 Server)上运行一个网站:site1.mysite.local

  • 我们使用.NET 4.0在IIS 7(Win2008 Server)上运行第二个网站:site2.mysite.local

在每个站点上,web.config包含StateServer和相同的machineKey:

On each site, the web.config contains the StateServer and the same machineKey:

<sessionState mode="StateServer" stateConnectionString="tcpip=STATESRV01:42424" />

<machineKey decryptionKey="EDCDA6DF458176504BBCC720B4E29348E252E652591179E2" validationKey="CC482ED6B5D3569819B3C8F07AC3FA855B2FED7F0130F55D8405597C796457A2F5162D35C69B61F257DB5EFE6BC4F6CEBDD23A4112C4519F55185CB5EB3DFE61"/>

我们还有一个PostRequestHandlerExecute事件处理程序来修改NET_SessionIdcookie以具有相同的根域和路径。

We also have a PostRequestHandlerExecute Event Handler to modify the "NET_SessionId" cookie to have the same root domain and path.

cookie.Domain = ".mysite.local";
cookie.Path = "/";

在global.asax文件中,我们有以下代码来修改Application_Start事件中的App Name :

In the global.asax file, we have the following code to modify the App Name in the Application_Start event:

    protected void Application_Start(object sender, EventArgs e)
    {
        string applicationName = "mysiteapp";

        // Change the Application Name in runtime.
        FieldInfo runtimeInfo = typeof(HttpRuntime).GetField("_theRuntime",
            BindingFlags.Static | BindingFlags.NonPublic);
        HttpRuntime theRuntime = (HttpRuntime)runtimeInfo.GetValue(null);
        FieldInfo appNameInfo = typeof(HttpRuntime).GetField("_appDomainAppId",
            BindingFlags.Instance | BindingFlags.NonPublic);

        appNameInfo.SetValue(theRuntime, applicationName);
    }



结果



两个站点都返回相同的会话ID,但是当我们尝试在site1上设置会话值时,site2不会返回值。

Result

Both sites return the same Session ID, but when we try to set a session value on site1, site2 does not return a value.

站点1(站点1。 mysite.local)结果

Session ID (Session.SessionID): a55jnfcscxd3f0hnwoik02pp
Session Value: True

网站2(site2.mysite.local)结果

Session ID (Session.SessionID): a55jnfcscxd3f0hnwoik02pp
Session Value: 



问题



根据我的理解,State Server会根据SessionID cookie的组合键入会话,机器密钥和我们尝试更新的应用程序名称,因此在两个站点上都是相同的。问题是,会话值不会在网站上共享。

Question

From my understanding, the State Server keys the session off of a combination of the SessionID cookie, the machine key, and the app name which we have tried to update so its the same across both sites. The problem is, the session value is not shared across the websites.

为什么不将SQL Server模式用于会话状态?

我们可能需要,但我们希望改用我们的状态服务器。

We might have to but we were hoping to use our State Server instead.

有没有人成功在多个服务器上具有多个Web应用程序的State Server?

Has anyone had success with State Server with multiple web applications across multiple servers?

推荐答案

.NET 3.5和.NET 4运行不同版本的CLR。对象序列化(用于在不使用InProc时存储会话状态)在.NET版本之间有所不同。该对象很可能无法在另一个平台上反序列化,因此它会无声地丢弃它。如果您将SQL Server用作会话状态服务器,则会遇到同样的问题。

.NET 3.5 and .NET 4 run different versions of the CLR. Object serialization (which is used for storing session state when not using InProc) differs between .NET versions. It's likely that the object is failing to be deserialized on another platform so it silently drops it. You would have the same problem if you use SQL Server as a Session State server too.

假设这是问题所以您必须确保两个站点都是在相同的.NET版本上,或执行您自己的序列化到磁盘或SQL Server。

Assuming this is the problem then you're going to have to ensure both sites are on the same .NET version, or perform your own serialization to disk or SQL Server.

这篇关于使用State Server在不同的.NET版本之间共享会话状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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