title: Change default session provider in ASP.NET
body: <p>I want to change my session proviced to statically typed - I just hate typing strings because of many many errors I do.</p>
  
  <p>What technology am I using? ASP.NET MVC via EXT.NET MVC </p>
  
  <p>I was trying to do that using web.config but the problem is that after add session state to it visual is not going to compile my code because of that session should be using strings as keys.</p>
  
  <p>I want to use session by enums such as : </p>
  
  <pre><code>public enum SessionEnum{Model}
  public class Bar{
  void foo(){
      Session[SessionEnum.Model] = "blah";
  }
  }
  </code></pre>
  
  <p>I am aware that I can create wrapper converting enums to strings but it's not very satisfying solution for me.</p>
  
  <pre><code>public class StorageWrapper{
      public object this[SessionEnum enum]{ get{return Session[enum.toString()]}; //+set
  }
  </code></pre>
  
  <p>What I did was create static object for base class for all of my controllers and then I was able to use it across them but after closing and opening the page again I wasn't able to get values from it. I guess I should serialize them somehow but I have no idea how.</p>
  
  <p>Is there any way to do that?</p>
  
  <p><strong>EDIT</strong>
  My session now looks like this : </p>
  
  <pre><code>[Serializable]
  public abstract class DataWrapper&lt;T&gt; : HttpSessionStateBase
  {
      Dictionary&lt;T, object&gt; Dictionary { get; set; } = new Dictionary&lt;T, object&gt;();
      public object this[T a]
      {
          get
          {
              try
              {
                  return Dictionary[a];
              }
              catch
              {
                  return null;
              }
          }
          set { Dictionary[a] = value; }
      } 
  }
  [Serializable]
  public class SessionWrapper : DataWrapper&lt;SessionNames&gt;
  {}
  public enum SessionNames { Model, Login, LastOpenedFile }
  </code></pre>