Currently, I am working with Asp.Net Core and MVC6 need to upload file size unlimited. I have searched its solution but still not getting the actual answer.
I have tried this link
If anyone have any idea please help.
Thanks.
Max Upload File Size in IIS and ASP.NET (. By default maximum upload size is set to 4096 KB (4 MB) by ASP.NET. To increase the upload limit add an appropriate section to your web.
The property, maxRequestLength indicates the maximum file upload size of 28.6MB, supported by ASP.NET. You cannot upload the files when the FileSize property is below the maxRequestLength value.
The other answers solve the IIS restriction. However, as of ASP.NET Core 2.0, Kestrel server also imposes its own default limits.
Github of KestrelServerLimits.cs
Announcement of request body size limit and solution (quoted below)
If you want to change the max request body size limit for a specific MVC action or controller, you can use the RequestSizeLimit
attribute. The following would allow MyAction
to accept request bodies up to 100,000,000 bytes.
[HttpPost] [RequestSizeLimit(100_000_000)] public IActionResult MyAction([FromBody] MyViewModel data) {
[DisableRequestSizeLimit]
can be used to make request size unlimited. This effectively restores pre-2.0.0 behavior for just the attributed action or controller.
If the request is not being handled by an MVC action, the limit can still be modified on a per request basis using the IHttpMaxRequestBodySizeFeature
. For example:
app.Run(async context => { context.Features.Get<IHttpMaxRequestBodySizeFeature>().MaxRequestBodySize = 100_000_000;
MaxRequestBodySize
is a nullable long. Setting it to null disables the limit like MVC's [DisableRequestSizeLimit]
.
You can only configure the limit on a request if the application hasn’t started reading yet; otherwise an exception is thrown. There’s an IsReadOnly
property that tells you if the MaxRequestBodySize
property is in read-only state, meaning it’s too late to configure the limit.
If you want to modify the max request body size globally, this can be done by modifying a MaxRequestBodySize
property in the callback of either UseKestrel
or UseHttpSys
. MaxRequestBodySize
is a nullable long in both cases. For example:
.UseKestrel(options => { options.Limits.MaxRequestBodySize = null;
or
.UseHttpSys(options => { options.MaxRequestBodySize = 100_000_000;
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