title: Why is HttpContext.Current null during the Session_End event?
body: <p>I want to count my users and this is the code below that is in my dll file:</p>
  
  <pre><code>public static class UserCount
  {
      public static void add()
      {
          HttpContext.Current.Application.Lock();
          int count = (int) HttpContext.Current.Application["CountOfUsers"];
          count++;
          HttpContext.Current.Application["CountOfUsers"]=count;
          HttpContext.Current.Application.UnLock();
      }
  
      public static void subtract()
      {   
          HttpContext.Current.Application.Lock();//error : HttpContext.Current is null. why?
          int count = (int) HttpContext.Current.Application["CountOfUsers"];
          count--;
          HttpContext.Current.Application["CountOfUsers"]=count;
          HttpContext.Current.Application.UnLock();
      }
  }
  </code></pre>
  
  <p>I have set <code>Session.TimeOut=1;</code>
  and after one minute the the method below in Global.asax file, this will run:</p>
  
  <pre><code>    protected void Session_End(object sender, EventArgs e)
      {
          UserCount.subtract();
      }
  </code></pre>
  
  <p>Why is <code>HttpContext.Current</code> null in the <code>subtract</code> method causing it to throw an exception?</p>