How to Increase the Max Upload File Size in Asp.Net

How to increase the max upload file size in ASP.NET?

This setting goes in your web.config file. It affects the entire application, though... I don't think you can set it per page.

<configuration>
<system.web>
<httpRuntime maxRequestLength="xxx" />
</system.web>
</configuration>

"xxx" is in KB. The default is 4096 (= 4 MB).

How to increase the limit on the size of the uploaded file?

Have you tried to decorate the controller action with [RequestSizeLimit(YOUR_MAX_TOTAL_UPLOAD_SIZE)] along with the changes in Startup.cs?

services.Configure<FormOptions>(opt =>
{
opt.MultipartBodyLengthLimit = YOUR_MAX_TOTAL_UPLOAD_SIZE;
});

btw, if you are planning to host the app on IIS, you can add web.config file to your project and configure the upload size there, rather than configuring it on the IIS server.

EDIT: as @XelaNimed's comment, adding the web.config file along with editing the startup.cs, got the code working.

<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
<environmentVariables />
</aspNetCore>
</system.webServer>
</location>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="YOUR_BYTES" />
</requestFiltering>
</security>
</system.webServer>
</configuration>

Change file upload limits for an ASP.NET Core 3.1 App using Azure App Service

This how we set it up in NET6, should work very similar in 3.1:

progam.cs

builder.WebHost.ConfigureKestrel(options =>
{
options.Limits.MaxRequestBodySize = 256_000_000;
})
.UseIISIntegration()

web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="256000000" />
</requestFiltering>
</security>
</system.webServer>
</configuration>

How do I increase the size of the .net core 2.1 file upload?

If you're using Multipart forms to upload the file, then you should change the limit here:

services.Configure<FormOptions>(x =>
{
x.ValueLengthLimit = 2147483648;
x.MultipartBodyLengthLimit = 2147483648;
x.MultipartHeadersLengthLimit = 2147483648;
});


Related Topics



Leave a reply



Submit