I am in the process of converting a large .NET Framework project to a .NET Core project, and I have come across the following code:
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);
}
}
There is no BufferOutput property on the HttpResponse class in .NET Core.
What is the equivalent of the HttpResponseBase.BufferOutput property in ASP.NET Core 2?
For enabling Buffering in Asp.Net Core, you could use UseResponseBuffering middleware in Startup like below:
app.UseResponseBuffering();
After applying the Buffering Middleware, if you want to disable buffer for specific requests, you could try code below:
var bufferingFeature = httpContext.Features.Get<IHttpBufferingFeature>();
bufferingFeature?.DisableResponseBuffering();
You can use IHttpResponseBodyFeature for response buffer or IHttpRequestBodyFeature for request buffer.
httpContext.Features.Get<IHttpResponseBodyFeature>().DisableBuffering()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With