title: HttpModule with filter - Writer method is called twice
body: <p>I have a HttpModule with a filter (PageFilter) where the Writer method of PageFilter is called twice for every page request, unfortunately not with the same result.</p>
  
  <p>The idea of the filter is to locate "" and insert some text/script in front of this. I have located a bunch of minor errors (and corrected them), but this error is playing tricks on me...</p>
  
  <p>The constructor og PageFilter is called once, but its writer method is called twice per request?</p>
  
  <p>below is the content of PageFilter.Writer (which runs twice)</p>
  
  <pre><code>string strBuffer = System.Text.UTF8Encoding.UTF8.GetString (buffer, offset, count); 
  
  try 
  {
      Regex eof = new Regex("&lt;/html&gt;", RegexOptions.IgnoreCase);
  
      if (!eof.IsMatch(strBuffer))
      {
         //(1)
         responseHtml.Append(strBuffer);
      }
      else
      {
          //(2)
          responseHtml.Append (strBuffer);
          string  finalHtml = responseHtml.ToString ();
          Regex   re = null;
  
          re = new Regex ("&lt;/body&gt;", RegexOptions.IgnoreCase);
          finalHtml = re.Replace(finalHtml, new MatchEvaluator(lastWebTrendsTagMatch));
          // Write the formatted HTML back
          byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes (finalHtml);
  
          responseStream.Write(data, 0, data.Length);       
  
         }
      }
      catch (Exception ex)
      {
         Logging.Logger(Logging.Level.Error, "Failed writing the HTML...", ex);
      }
  </code></pre>
  
  <p>First time the method runs case (1) runs and on 2nd case (2) runs... this is not excatly what I want, anyone knows why and/or how I can make it work (consistently)?</p>