Request size limit in aspnet core application hosted on azure app service

Kirankumar Bharsadiya 40 Reputation points
2024-09-09T13:44:22.67+00:00

I have my aspnet core 8 application hosted on azure app service. In the app, when I upload a file it give me request body size related error. I configured following code .


//Solution 1 : 
services.Configure
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,610 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,007 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,902 questions
{count} votes

Accepted answer
  1. Sergio Andrés Vargas Acosta 75 Reputation points
    2024-09-10T02:33:22.5666667+00:00

    Hi.

    To address the request body size limit issue in an ASP.NET Core 8 application hosted on Azure App Service, you can increase this limit in your code. In the Program.cs file, configure the maximum allowed request body size using services.Configure<FormOptions>(options => { options.MultipartBodyLengthLimit = 104857600; });, where 104857600 represents 100 MB. Also, ensure that you verify the Azure App Service configuration, although the main adjustment is typically done in the application code.

    // Configure services``

    builder.Services.Configure<FormOptions>(options => { ``// Set the maximum file size (e.g., 100 MB)`` options.MultipartBodyLengthLimit = ``104857600``; ``// 100 MB

    });

    User's image

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. SurferOnWww 3,126 Reputation points
    2024-09-10T03:45:27.2833333+00:00

    I guess that your ASP.NET Core application is hosted by the IIS or Kestrel. If so, there is a limitation in maximum request body size of 30,000,000 bytes by default as described in the Microsoft document Upload files in ASP.NET Core.

    Kestrel maximum request body size: For apps hosted by Kestrel, the default maximum request body size is 30,000,000 bytes, which is approximately 28.6 MB.

    IIS: The default request limit (maxAllowedContentLength) is 30,000,000 bytes, which is approximately 28.6 MB.

    It can be customized as described in the above document.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.