Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase upload request length limit in Kestrel

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

I know that when running IIS, the limits can be changed via web.config:

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

How can you do the equivalent while running the new ASP.NET Core Kestrel web server?

I get the exception "Request body too large."

like image 330
ToddBFisher Avatar asked Oct 13 '17 21:10

ToddBFisher


People also ask

How many connections can Kestrel handle?

The default value is 4096.

How do I increase request timeout in .NET core?

But according to the documentation you can just add web. config to your project and specify this (and other) setting value: Setting the RequestTimeout="00:20:00" on the aspNetCore tag and deploying the site will cause it not to timeout.

What does webhost CreateDefaultBuilder () do?

CreateDefaultBuilder()Initializes a new instance of the WebHostBuilder class with pre-configured defaults.


1 Answers

I found this helpful announcement that confirms there is a 28.6 MB body size limit starting with ASP.NET Core 2.0, but more importantly shows how to get around it!

To summarize:

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

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

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

For additional clarity, you can also refer to the Kestrel options documentation.

like image 167
ToddBFisher Avatar answered Sep 20 '22 18:09

ToddBFisher