As a part of the requirement, I need to share a single session between 2 different applications (hosted on different machine) within diffrent domain. (ex: app1.domain.com and app2.domain.com)
I am using Sql Server session management and both the applications are pointing to one same server to store session. In both web applications, machine key is defined same and both web servers pointing to same Server where I am running State Server service for session management.
But when I redirect from one application to another application, I am unable to read the session value in the second application which is initiated in the first application. Need your suggestions. Thanks!
Below changes I am doing on web.config of both the applications:
<sessionState mode="SQLServer"
cookieless="false"
timeout="20"
sqlConnectionString="data source= DESKTOP-565; initial catalog=ASPState; user id=sa; password=*********;"
allowCustomSqlDatabase="true" />
Also in Init() method in Global.asax, I am converting Application domain name to one single name so that session can be shared between 2 apps. (this method is written on both application
public override void Init()
{
base.Init();
try
{
// Get the app name from config file...
string appName = "/lm/w3svc/5/root";
if (!string.IsNullOrEmpty(appName))
{
foreach (string moduleName in this.Modules)
{
IHttpModule module = this.Modules[moduleName];
SessionStateModule ssm = module as SessionStateModule;
if (ssm != null)
{
FieldInfo storeInfo = typeof(SessionStateModule).GetField("_store", BindingFlags.Instance | BindingFlags.NonPublic);
SessionStateStoreProviderBase store = (SessionStateStoreProviderBase)storeInfo.GetValue(ssm);
if (store == null) //In IIS7 Integrated mode, module.Init() is called later
{
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, appName);
}
else
{
Type storeType = store.GetType();
if (storeType.Name.Equals("OutOfProcSessionStateStore"))
{
FieldInfo uribaseInfo = storeType.GetField("s_uribase", BindingFlags.Static | BindingFlags.NonPublic);
uribaseInfo.SetValue(storeType, appName);
}
}
}
}
}
}