Aug 22 2024 11:36 PM
Using .Net core 8.0 and App service Deployment , need to increase the file upload size limit to 50 mb
implemented following things in the local and its working as expected but when it is deployed to app services its not working
Program.cs file
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel((context, options) =>
{
// Handle requests up to 50 MB
options.Limits.MaxRequestBodySize = 52428800;
})
.UseStartup<Startup>();
})
.UseSerilog()
;
startup file:
app.Use(async (context, next) =>
{
context.Features.Get<IHttpMaxRequestBodySizeFeature>().MaxRequestBodySize = 104857600; // unlimited I guess
await next.Invoke();
});
---
services.Configure<FormOptions>(o => // currently all set to max, configure it to your needs!
{
o.ValueLengthLimit = int.MaxValue;
o.MultipartBodyLengthLimit = 104857600;
o.MultipartBoundaryLengthLimit = int.MaxValue;
o.MultipartHeadersCountLimit = int.MaxValue;
o.MultipartHeadersLengthLimit = int.MaxValue;
o.ValueCountLimit = int.MaxValue;
});
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = 104857600; // Remove any limit
});
services.Configure<KestrelServerOptions>(options =>
{
options.Limits.MaxRequestBodySize = 104857600; // Remove limits for Kestrel
});
-----
in app settings file
"Kestrel": {
"Limits": {
"MaxRequestBodySize": 52428800
}
},
---
In the project configuration we are not using web.config file , we need alternate solution , if we use the web.config settings
<system.web>
<httpRuntime targetFramework="4.8" maxRequestLength="1048576" executionTimeout="120" />
</system.web>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="4294967295" />
</requestFiltering>
</security>
With this configuration it is working as expected in the app service but we are not web.config file as it is automatically generated
Aug 23 2024 02:59 PM
Aug 24 2024 05:05 AM
@sdtslmn Application gateway is disabled and front door is configuraton is set a per the plan, the thing here is if i use IHttpPosetedFile instead of IFormFile the same app service works.
Sep 01 2024 05:34 PM
Please ensure that the configurations are correctly applied and not overridden by other settings between Program.cs and Startup.cs
Sep 01 2024 06:07 PM