1

I am sending a page to the client in chunks, by calling Response.Flush() in the middle of my page. This is so the browser will get the first part of the html, and can start downloading resources while my server continues to process the rest of the request.

Because of certain 3rd party services between my IIS server and my client (CDN, Firewall, Load Balancing, etc.) I need to set the header Transfer-Encoding: Chunked so they will know that the response will return in chunks.

I try setting the header by calling : Response.Headers.Add("Transfer-Encoding", "chunked");

For some reason when i do this, I get a blank page back after waiting quite a long time, even when contacting my IIS server directly, without going through all the 3rd parties. When attaching to process to debug, I don't see any errors.
Removing the 'Transfer-Encoding' header works, but I need this header for some of the 3rd parties I'm using.

Anyone know how I can set this header in my web application ??

Btw - I also tried setting this header in 'Response Headers' section in IIS directly, and the response is still empty when doing this.

4

2 回答 2

1

根据Wikipedia 上的描述,分块传输编码要求以特定方式对响应主体进行编码,所描述格式的要点之一是:

每个块以它嵌入的数据的八位字节数开始,以 ASCII 中的十六进制数表示,后跟可选参数(块扩展)和终止 CRLF 序列,然后是块数据。该块由 CRLF 终止。如果提供了块扩展,则块大小以分号结尾,后跟扩展名和可选的等号和值。

据我所知,调用Response.Flush()不会生成这个特定的标记。它只是将任何缓冲的响应内容清空给客户端。

您可以查看“服务器何时使用分块传输编码?” 在这个答案中: https ://stackoverflow.com/a/2711405/1236044

这似乎意味着,通过正确的设置,IIS 应该在需要时自动切换到块传输编码

于 2013-08-27T12:00:15.420 回答
0

如果禁用缓冲,服务器将使用分块传输编码:

设置context.Response.BufferOutputfalse

根据这个问题

您可能需要进一步设置Server.ScriptTimeout(以秒为单位)以避免脚本被中断。

于 2013-08-25T15:15:14.700 回答