ASP.NET Core 2 中 HttpResponseBase.BufferOutput 属性的等价物是什么?

tac*_*cos 6 asp.net-core

我正在将大型 .NET Framework 项目转换为 .NET Core 项目,并且遇到以下代码:

public class ContentStreamingResult : ActionResult {

    private Action<Stream> _onExecuteAction;

    public ContentStreamingResult(Action<Stream> onExecuteAction) {
        _onExecuteAction = onExecuteAction;
    }

    public override void ExecuteResult(ControllerContext context) {
        var httpContext = context.HttpContext;
        httpContext.Response.BufferOutput = false;
        _onExecuteAction(httpContext.Response.OutputStream);
    }
}
Run Code Online (Sandbox Code Playgroud)

.NET Core 中BufferOutputHttpResponse类没有属性。

什么是HttpResponseBase.BufferOutputASP.NET Core 2中的属性?

Tao*_*hou 6

Buffering在 Asp.Net Core 中启用,您可以使用如下UseResponseBuffering中间件Startup

app.UseResponseBuffering();
Run Code Online (Sandbox Code Playgroud)

应用后Buffering Middleware,如果您想禁用特定请求的缓冲区,您可以尝试以下代码:

var bufferingFeature = httpContext.Features.Get<IHttpBufferingFeature>();
bufferingFeature?.DisableResponseBuffering();
Run Code Online (Sandbox Code Playgroud)

  • 如果您只想为一个请求启用响应缓冲(例如,将图像字节流式传输到响应?) (4认同)