title: Using a static variable in an ASP.Net HttpModule
body: <p>I'm using an HttpModule to intercept each requests to my website in order to assign them authentication cookies, this is only a preliminary version but I'm having a static List in my HttpModule and for each new request I'm adding an element in the list. For testing purposes I'm writing them all to the response in order to see if my method is working but it is only ever giving me two values no matter how many users are in the list.</p>
  
  <p>Here is a sample of my code, I've kept it simple by replacing the list of users with a list of strings.</p>
  
  <pre><code>public class SCCModule : IHttpModule
  {
      private static List&lt;string&gt; _users = new List&lt;string&gt;();
  
      public void Init(HttpApplication context)
      {
          context.PreRequestHandlerExecute += OnPreRequestHandlerExecute;
      }
      public void Dispose()
      {
  
      }
      public void OnPreRequestHandlerExecute(Object source, EventArgs e)
      {
          HttpApplication app = (HttpApplication)source;
          HttpResponse response = app.Context.Response;
          HttpRequest request = app.Context.Request;
  
          _users.Add("A user from " + DateTime.Now + "&lt;/br&gt;");
  
          foreach(var u in _users)
          {
              response.Write(u);
          }
      }
  }
  </code></pre>
  
  <p>When loading a sample index.html from the website, it gives me : </p>
  
  <p>A user from 10/18/2012 3:37:33 PM</p>
  
  <p>A user from 10/18/2012 3:37:35 PM</p>
  
  <p>Info on my setup : I'm running IIS7.5 to which I've added a Module, it is the first in order of priorities of execution. I have enabled Debugging in the web.config. My VisualStudio is set to build debug configuration and there is a post build event to directly copy my DLL to the bin folder of my website. I am attaching myself to the w3wp.exe process in order to debug it.</p>
  
  <p>An interesting fact : when debugging. The first two times I hit refresh on the index.html page are going to trigger my breakpoint and after that it won't. Any new URI that I enter will only hit the breakpoint two times.</p>
  
  <p>So why is it that only two results seem to go through even though I can refresh ten times ?</p>
  
  <p>Fiddler result : 
  <img src="https://i.stack.imgur.com/SFSRM.png" alt="enter image description here"></p>