title: Are static class instances unique to a request or a server in ASP.NET?
body: <p>On an ASP.NET website, are static classes unique to each web request, or are they instantiated whenever needed and GCed whenever the GC decides to disposed of them?</p>
  
  <p>The reason I ask is because I've written some static classes before in C# and the behavior is different than I would have expected. I would have expected static classes to be unique to each request, but it doesn't seem like that is the case.</p>
  
  <p>If they are not unique to each request, is there a way to allow them to be?</p>
  
  <p><strong>UPDATE:</strong><br>
  The answer driis gave me was exactly what I needed. I was already using a singleton class, however it was using a static instance and therefore was being shared between requests even if the users were different which in this case was a bad thing. Using <code>HttpContext.Current.Items</code> solves my problem perfectly. For anyone who stumbles upon this question in the future, here is my implementation, simplified and shortened so that it easy to understand the pattern:</p>
  
  <pre><code>using System.Collections;
  using System.Web;
  
  public class GloballyAccessibleClass
  {
      private GloballyAccessibleClass() { }
  
      public static GloballyAccessibleClass Instance
      {
          get
          {
              IDictionary items = HttpContext.Current.Items;
              if(!items.Contains("TheInstance"))
              {
                  items["TheInstance"] = new GloballyAccessibleClass();
              }
              return items["TheInstance"] as GloballyAccessibleClass;
          }
      }
  }
  </code></pre>