フィルター (PageFilter) を持つ HttpModule があります。PageFilter の Writer メソッドはページ要求ごとに 2 回呼び出されますが、残念ながら同じ結果にはなりません。
フィルターの考え方は、"" を見つけて、この前にテキスト/スクリプトを挿入することです。たくさんの小さなエラーを見つけて修正しましたが、このエラーは私を悩ませています...
PageFilter のコンストラクターは 1 回呼び出されますが、そのライター メソッドは要求ごとに 2 回呼び出されますか?
以下は PageFilter.Writer の内容です(2回実行されます)
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);
}
メソッドが最初に実行されると、ケース (1) が実行され、2 番目のケース (2) が実行されます...これは私が望むものではありません。