Home > Mobile >  http error 413.1 - request entity too large in .net Core
http error 413.1 - request entity too large in .net Core

Time:04-29

I am getting this error saying

HTTP Error 413.1 - Request Entity Too Large
The request filtering module is configured to deny a request that exceeds the request content length

In order to fix this issue, I did the following:

Increased the RequestFormLimits to int.MaxValue in my controller like so:

 [RequestFormLimits(ValueLengthLimit = int.MaxValue, MultipartBodyLengthLimit = int.MaxValue)]

Added the following code in my startup.cs file:

      services.Configure<Microsoft.AspNetCore.Http.Features.FormOptions>(x =>
        {
            x.ValueLengthLimit = int.MaxValue;
            x.MultipartBodyLengthLimit = int.MaxValue; // In case of multipart
        });

Added the following in my web.config file

 <system.webServer>
      <security>
        <requestFiltering>
          <!-- 2 GB -->
          <requestLimits maxAllowedContentLength="2147483648" />
        </requestFiltering>
      </security>

I tried to upload 1 GB file and I am getting an error saying :

HTTP Error 413.1 - Request Entity Too Large

any help will be highly appreciated

CodePudding user response:

If your are using .net core 3.1 or lower,try to add the codes in your startup class:

services.Configure<IISServerOptions>(options =>
{
    options.MaxRequestBodySize = 2147483648;
});

The official document:https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-3.1#iis-1

  • Related