我有一个带有过滤器(PageFilter)的 HttpModule,其中 PageFilter 的 Writer 方法为每个页面请求调用两次,不幸的是结果不同。
过滤器的想法是定位“”并在其前面插入一些文本/脚本。我找到了一堆小错误(并更正了它们),但是这个错误在欺骗我......
构造函数 og PageFilter 被调用一次,但它的 writer 方法每次请求被调用两次?
下面是 PageFilter.Writer 的内容(运行两次)
string strBuffer = System.Text.UTF8Encoding.UTF8.GetString (buffer, offset, count);
try
{
Regex eof = new Regex("</html>", 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 ("</body>", 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);
}
该方法第一次运行 case (1) 运行并在第二个 case (2) 运行......这不是我想要的,任何人都知道为什么和/或如何让它工作(一致地)?