ASP和WCF之间的会话共享

时间:2015-03-03 10:16:52

标签: c# asp.net wcf session ninject

我们尝试为ASP应用程序和WCF服务共享相同的会话。 在过去,我们建立了一个POC,它运作良好。我们能够在ASP和WCF中拥有相同的会话。但是现在,当我们尝试在当前项目中实施POC时,我们无法检索相同的会话。

我们这样做的方式是:

1)powershell命令启用会话

2)将值添加到web.config

  • Same machineKey
  • 相同的SessionState(模式SQLServer)
  • 相同的httpModule(配置相同的会话,会话应用程序)
  • 相同的模块(指向与httpModule相同的模块)
  • < serviceHostingEnvironment aspNetCompatibilityEnabled =" true" multipleSiteBindingsEnabled ="真" />

此外:

  • 在ASP和WCF上,我们有一个会话(来自HttpContext.Current.Session),但它们是不同的(对于 示例sessionID不同)
  • 调试时,模块仅在ASP端触发,因此问题可能在WCF中
  • 我们使用Ninject我们的应用程序(不在POC中),但是我们将模块绑定在bootstrapper中

供参考:

public class SharedSessionModule : IHttpModule
{
    public void Init(HttpApplication context)
    {
        try
        {
            string appName = Configuration.Session.AppName;
            if (string.IsNullOrEmpty(appName)) return;

            var runtimeInfo = typeof (HttpRuntime).GetField("_theRuntime", BindingFlags.Static | BindingFlags.NonPublic);
            var theRuntime = (HttpRuntime) runtimeInfo.GetValue(null);
            var appNameInfo = typeof (HttpRuntime).GetField("_appDomainAppId", BindingFlags.Instance | BindingFlags.NonPublic);
            appNameInfo.SetValue(theRuntime, appName);
        }
        catch (Exception ex)
        {
            //Logging
        }
    }

    public void Dispose()
    {
        // Nothing to dispose.
    }
}

有谁知道问题可能是什么? (我想可能是在我使用Ninject,WCF时)

0 个答案:

没有答案
相关问题