2011-02-08 46 views
7

我试图创建一个改变Response.Filter像这样 (此演示只是设置过滤器回本身)一个的HttpModule:IIS 7.5 ASP.NET的HttpModule - 设置Response.Filter结果块编码

public class ContentTrafficMonitor : IHttpModule 
{ 
    public void Init(HttpApplication context) 
    { 
    context.BeginRequest += OnBeginRequest; 
    } 

    public void Dispose() 
    { 
    } 

    private static void OnBeginRequest(object sender, EventArgs e) 
    { 
    var application = (HttpApplication) sender; 
    application.Response.Filter = application.Response.Filter; 
    } 

}

否则设置响应的传输编码分块到,而不是使用Content-Length报头。

如果我删除设置了Response.Filter的行,则响应的标头为Content-Length。我们的应用程序取决于Content-Length标题,有什么办法可以防止这种行为?

+0

我也有这个问题。有没有人有任何解决办法? – Mahyar 2015-01-14 09:36:02

回答

1

我的猜测是,设置过滤器会干扰输出的正常缓冲,因此输出现在被分块。

也许你可以通过让你的过滤器读取直到结束来模仿行为,即根据你读的内容写出所有读出的内容,根据你所读的内容设置内容长度标题的所有输出&。

这只是一个猜测,虽然我害怕。

Simon