HttpModule工作正常(“hello”替换为“hello world”),但由于某些原因,当将模块添加到Web.config时,WebForms上的图像不显示。从Web.config中删除该模块时,将显示WebForms上的图像。HttpModule,Response.Filter和图像未显示
有谁知道为什么?
使用或不使用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);
}
}
//过滤器 - 替换“你好”与“世界你好”
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);
}
}
使事件处理程序在.aspx页面上应用筛选器只做了它。谢谢您的帮助。 – thd 2009-09-15 22:56:04