I have read the MaxResponseBufferSize can be set at startup via code like
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(x => x.Limits.MaxResponseBufferSize = 10485760).UseStartup<Startup>();
});
Is there a porvisioning of setting that limit on controller/action level instead at startup. Like adding it in some attribute there
Short answer: no.
MaxResponseBufferSize
limit is a low-level Kestrel implementation detail that is independent of HttpContext
. It has no idea which controller or action is executing at the moment (or finished executing), so you cannot tweak the way it works within an action.
The reason RequestSizeLimit
is configurable unlike MaxResponseBufferSize
is that the request body is not read by default unless you implicitly (using model binding [FromBody]
) or explicitly (Request.Body.Read*
methods) read the body stream from the request. This happens at the endpoint level, so ASP.NET Core exposes relevant piping to make this easier to configure, if needed.