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