Increase Kestrel Download Request Length Limit

I am running an ASP.NET Core web application and want to upload large files.

I know that when starting IIS, the restrictions can be changed using web.config :

 <httpRuntime maxRequestLength="1048576" /> ... <requestLimits maxAllowedContentLength="1073741824" /> 

How can you make the equivalent of starting a new ASP.NET Core Kestrel web server?

I get the exception "The request body is too large."

+5
source share
1 answer

I found this useful announcement that confirms that the 28.6 MB body size limit starts with ASP.NET Core 2.0, but, more importantly, shows how to get around it!

Summarizing:

For a single controller or action, use the [DisableRequestSizeLimit] attribute to not have restrictions, or [RequestSizeLimit(100_000_000)] to specify a user limit.

To change it globally inside the BuildWebHost() method inside the Program.cs file, add the .UseKestrel parameter below:

 WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseKestrel(options => { options.Limits.MaxRequestBodySize = null; } 

For additional clarity, you can also refer to the Kestrel Version Documentation .

+7
source

Source: https://habr.com/ru/post/1272607/


All Articles