Sharing Session State between different .NET Versions using State Server

孤街醉人 提交于 2019-12-03 10:32:29

.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.

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.

StateServer and SQLServer state management also uses the application path (in addition to the application name) in creating the key for session data.

Your application is showing the same SessionID due to the cookie being read by both apps, however the application path must be the same as well to actually read the same session data on the state server.

You can change that to the same value with an extra overwrite in your Application_Start for this variable:

FieldInfo appPathInfo = typeof(HttpRuntime).GetField("_appDomainAppPath",
     BindingFlags.Instance | BindingFlags.NonPublic);

appPathInfo .SetValue(theRuntime, applicationName);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!