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."
The default value is 4096.
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.
CreateDefaultBuilder()Initializes a new instance of the WebHostBuilder class with pre-configured defaults.
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.
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