【问题标题】:IAsyncEnumerable<T> in ASP.NET Core, deploying on iis is not supported streaming behaviour?ASP.NET Core 中的 IAsyncEnumerable<T>,不支持在 iis 上部署的流式传输行为?
【发布时间】:2022-01-22 08:15:15
【问题描述】:
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
    [HttpGet]
    public IAsyncEnumerable<int> Get()
    {
        return FetchItems();
    }

    static async IAsyncEnumerable<int> FetchItems()
    {
        for (int i = 1; i <= 10; i++)
        {
            await Task.Delay(1000);
            yield return i;
        }
    }
}

参考文章地址如下: IAsyncEnumerable with yield in C#

正确的效果应该如下:streaming behaviour

但是当我在 IIS 中部署程序时,它不起作用。

结果仍然会被缓存并一次性输出。

谁能告诉我有没有解决办法?

HttpContext.Features.Get().DisableBuffering() 这行得通,谢谢@Jeremy Lakeman

【问题讨论】:

  • 所以在部署到 IIS 时会有一些缓冲?
  • HttpContext.Features.Get&lt;IHttpResponseBodyFeature&gt;().DisableBuffering() 可能有用吗?

标签: c# iis asp.net-core-webapi .net-6.0 asp.net-core-6.0


【解决方案1】:

有一个 IIS 功能可以缓冲异步流:动态压缩。如果为 IIS 安装了动态压缩功能,它将缓冲并尝试压缩基于文本的响应。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-08
    • 2017-03-16
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    • 1970-01-01
    • 2019-10-09
    • 1970-01-01
    相关资源
    最近更新 更多