我正在将一个大型.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
属性是什么?
答案 0 :(得分:1)
要在Asp.Net Core中启用Buffering
,可以在UseResponseBuffering
中使用Startup
中间件,如下所示:
app.UseResponseBuffering();
应用Buffering Middleware
后,如果要为特定请求禁用缓冲区,则可以尝试以下代码:
var bufferingFeature = httpContext.Features.Get<IHttpBufferingFeature>();
bufferingFeature?.DisableResponseBuffering();