0

I'm trying to setup two Windowz boxes (win1, win2) between a varnish round robin loab balancer.

Session state for the application is both configured as "State server" pointing on a third machine (x.y.w.z). Calling telnet x.y.w.z 42424 is ok from both win1 and win2. Al machines have same OS version. Both machines have the same machine key enter image description here

I've dropped in ans aspx debugging page copied from http://pardini.net/blog/2011/02/17/the-ultimate-asp-net-session-state-debugging-tool/ and it shows two different machine keys.

enter image description here

i can see that AppDomainAppId is different; how can I change it? What is happening here?

lrkwz
  • 6,105
  • 3
  • 36
  • 59

1 Answers1

0

As suggested in Sharing session state over multiple ASP.NET applications with ASP.NET state server I've added a hook into Global.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Context;
using NHibernate.Mapping.Attributes;
using System.Web.SessionState;
using System.Reflection;

/// <summary>
/// Summary description for Global
/// </summary>
public class Global : System.Web.HttpApplication
{
  public static ISessionFactory SessionFactory;

private static Configuration _configuration;

public override void Init()
{
    base.Init();
    foreach (string moduleName in this.Modules)
    {
        string appName = "MYAPPNAME";
        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);
                }
            }
        }
    }
}
(...)
lrkwz
  • 6,105
  • 3
  • 36
  • 59