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
How to Dynamically Create Generic C# Object Using Reflection
How to Exclude Property from Json Serialization
Convert Datatable to Json in C#
A Potentially Dangerous Request.Path Value Was Detected from the Client (*)
Difference Between Null and System.Dbnull.Value
How to Create Linq Expression Tree to Select an Anonymous Type
The Foreach Identifier and Closures
Get String Between Two Strings in a String
Integer Summing Blues, Short += Short Problem
Ipc Mechanisms in C# - Usage and Best Practices
Dynamic Where Clause (Or) in Linq to Entities
What Does "Use of Unassigned Local Variable" Mean
Json.Net Serialization of Type With Polymorphic Child Object