HttpModuleは正常に機能します(「hello」は「helloworld」に置き換えられます)が、モジュールがWeb.configに追加されたときに、何らかの理由でWebFormsの画像が表示されません。モジュールがWeb.configから削除されると、WebForms上の画像が表示されます。
誰かが理由を知っていますか?
HttpModuleの有無にかかわらず生成されるHTMLは、まったく同じです。
//The HttpModule
public class MyModule : IHttpModule
{
#region IHttpModule Members
public void Dispose()
{
//Empty
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(OnBeginRequest);
application = context;
}
#endregion
void OnBeginRequest(object sender, EventArgs e)
{
application.Response.Filter = new MyStream(application.Response.Filter);
}
}
//フィルター-「hello」を「helloworld」に置き換えます
public class MyStream : MemoryStream
{
private Stream outputStream = null;
public MyStream(Stream output)
{
outputStream = output;
}
public override void Write(byte[] buffer, int offset, int count)
{
string bufferContent = UTF8Encoding.UTF8.GetString(buffer);
bufferContent = bufferContent.Replace("hello", "hello world");
outputStream.Write(UTF8Encoding.UTF8.GetBytes(bufferContent), offset, UTF8Encoding.UTF8.GetByteCount(bufferContent));
base.Write(buffer, offset, count);
}
}