【发布时间】: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<IHttpResponseBodyFeature>().DisableBuffering()可能有用吗?
标签: c# iis asp.net-core-webapi .net-6.0 asp.net-core-6.0