I'm getting the following error while uploading large (38 MB) file using file upload on .NET 6 application deployed on Azure using Chrome browser:
I googled and found 2 solutions. It works fine in my local environment but not working after I deployed it to Azure.
Solution 1: In Program.cs
file
builder.Services.Configure<KestrelServerOptions>(options =>
{
options.Limits.MaxRequestBodySize = long.MaxValue;
});
builder.Services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = long.MaxValue;
});
Solution 2: ConfigureServices
method in Startup.cs
file
services.Configure<FormOptions>(options =>
{
options.MultipartBodyLengthLimit = long.MaxValue;
});
To work with large files, we need to make sure the
maxAllowedContentLength
andmaxRequestLength
is set correctly according to the request and file size inWeb.config
file.maxRequestLength
in<system.web>
:Thanks @Thomas for the comments
maxAllowedContentLength
in security sectionAs mentioned in the MSDoc, Add
maxAllowedContentLength
in the security tag.Thanks @[bhawanisingh] for clear steps.
Refer this blog for more details on how to work with large files.
When you deploy
.Net Core App
to Azure App Service (Windows / Linux),web.config
file be generated automatically in the deployed files (with basic settings).Windows:
Linux:
You can even add the
web.config
file locally in the application root directory and deploy along with other files.