I need ability to set the session state provider in code rather than web.config. I have tried adding in code in 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 the Session is reverting back to InProc Mode and not Custom. Is there a way to declare the provider in code?
As Brian Webster mentioned above, the only thing I've found on this is on this page.