title: Using static variables instead of Application state in ASP.NET
body: <p>I plane to use static variables instead of Application state in ASP.NET and am wondering if this is correct approach:</p>
  
  <pre><code>[Global.asax.cs]
  
  ...
  
  public class Global : System.Web.HttpApplication
  {
      void Application_Start(object sender, EventArgs e)
      {
          // Code that runs on application startup
  
      }
  
      ...
  
      private static Dictionary&lt;string, object&gt; cacheItems = new Dictionary&lt;string, object&gt;();
      private static object locker = new object();
  
      public static Dictionary&lt;string, object&gt; CacheItems
      {
          get
          {
              lock (locker)
              {
                  return cacheItems;
              }
          }
  
          set
          {
              lock (locker)
              {
                  cacheItems = value;
              }
          }
      }
  
      public static void RemoveCacheItem(string key)
      {
          cacheItems.Remove(key);
      }
  
      ...
  }
  </code></pre>
  
  <p>As you can see I use automatically created Global.asax (and code behind) file. I've added some static variables and methods. I can use them after in this manner:</p>
  
  <pre><code>[some .cs file]
  foreach(KeyValuePair&lt;string, object&gt; dictItem in Global.CacheItems)
  {
      ...
  </code></pre>
  
  <p>Is this the right way or I should create new class instead of existing Global? If I should create new class how can I do that and where?</p>