title: How session state provider set in Application_Start
body: <p>I need ability to set the session state provider in code rather than web.config. I have tried adding in code in Application_Start</p>
  
  <pre><code> 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;
  </code></pre>
  
  <p>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?</p>