How the Session State Provider is set to Application_Start

I need the ability to set the session state provider in code, not web.config. I tried adding code to 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;

      

But the problem is that the session falls back to InProc mode, not user mode. Is there a way to declare the provider in code?

+3


source to share


1 answer


As Brian Webster mentioned above, the only thing I found on this one is this page .



0


source







All Articles