【问题标题】:IIS 7.5 ASP.NET HttpModule - Setting Response.Filter results in chunked encodingIIS 7.5 ASP.NET HttpModule - 设置 Response.Filter 会导致分块编码
【发布时间】:2011-06-23 17:18:33
【问题描述】:

我正在尝试创建一个像这样更改Response.Filter 的HttpModule (对于这个演示,只需将过滤器设置回自身):

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 标头,有没有办法防止这种行为?

【问题讨论】:

  • 我也有这个问题。有人有解决办法吗?

标签: asp.net iis iis-7 httpmodule content-length


【解决方案1】:

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

也许你可以通过让你的过滤器读取到最后来模仿这种行为,即在你写出所有内容之前,获取所有输出并根据你读过的内容设置内容长度标题。

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

西蒙

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-25
    • 2012-06-21
    • 2013-01-06
    • 2016-12-17
    • 1970-01-01
    相关资源
    最近更新 更多