【发布时间】:2009-09-13 13:17:48
【问题描述】:
HttpModule 工作正常(“hello”被替换为“hello world”),但由于某些原因,当模块添加到 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”替换为“hello world”
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);
}
}
【问题讨论】:
标签: c# asp.net httpmodule