什么等效于ASP.NET Core 2中的HttpResponseBase.BufferOutput属性?

时间:2018-09-27 17:52:43

标签: 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);
    }
}

.NET Core中的BufferOutput类上没有HttpResponse属性。

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

1 个答案:

答案 0 :(得分:1)

要在Asp.Net Core中启用Buffering,可以在UseResponseBuffering中使用Startup中间件,如下所示:

app.UseResponseBuffering();

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

var bufferingFeature = httpContext.Features.Get<IHttpBufferingFeature>();
bufferingFeature?.DisableResponseBuffering();