3

我需要在代码而不是 web.config 中设置会话状态提供程序的能力。我尝试在 Application_Start 中添加代码

 System.Configuration.Configuration _configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/");

 var sessionStateSection =
                (System.Web.Configuration.SessionStateSection)_configuration.GetSection("system.web/sessionState");
            sessionStateSection.Providers.Clear();
            var customSessionStateProvider = new ProviderSettings(DEFAULT_SESSION_PROVIDER, DEFAULT_MEMBERSHIP_PROVIDER);
            customSessionStateProvider.Parameters.Add(CONNECTION_STRING_NAME, DEFAULT_CONNECTION);
            sessionStateSection.Providers.Add(customSessionStateProvider);
            sessionStateSection.Mode = System.Web.SessionState.SessionStateMode.Custom;
            sessionStateSection.Timeout = new TimeSpan(0, 20, 0);
            sessionStateSection.CustomProvider = DEFAULT_SESSION_PROVIDER;

但问题是会话正在恢复到 InProc 模式而不是自定义。有没有办法在代码中声明提供者?

4

1 回答 1

0

正如上面提到的布赖恩韦伯斯特(Brian Webster),我在此页面上找到的唯一内容是在此页面上

于 2013-03-06T19:17:47.437 回答