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
maxAllowedContentLengthandmaxRequestLengthis set correctly according to the request and file size inWeb.configfile.maxRequestLengthin<system.web>:Thanks @Thomas for the comments
maxAllowedContentLengthin security sectionAs mentioned in the MSDoc, Add
maxAllowedContentLengthin 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 Appto Azure App Service (Windows / Linux),web.configfile be generated automatically in the deployed files (with basic settings).Windows:
Linux:
You can even add the
web.configfile locally in the application root directory and deploy along with other files.