skip to content
Khalid Abuhakmeh logo Khalid Abuhakmeh

Increase the ASP.NET Core File Upload Limit (Fix 413 Errors)

Raise the ASP.NET Core upload limit: Kestrel MaxRequestBodySize, FormOptions, RequestSizeLimit, IIS maxAllowedContentLength, and how to fix 413 errors.

6 min read Updated

To increase the upload limit in ASP.NET Core, raise MaxRequestBodySize on Kestrel (default 30,000,000 bytes, about 28.6 MB), or put [RequestSizeLimit] on the one endpoint that needs more. If the upload is a multipart form, also check FormOptions.MultipartBodyLengthLimit (default 128 MB). Behind IIS, maxAllowedContentLength in web.config has its own 30,000,000-byte default. Updated November 2026.

Every layer between the browser and your handler can reject a request. An upload that fails with 413 Payload Too Large (or Request Entity Too Large) has hit one of them. This post covers each limit, what it defaults to, and how to change it on .NET 10. I verified the code below against a scratch ASP.NET Core app on net10.0; the results are in the verification section.

What is the default file upload limit in ASP.NET Core?

ASP.NET Core has several limits, and which one applies depends on where your app runs and how the file arrives.

Setting Where it applies Default Scope
KestrelServerLimits.MaxRequestBodySize Kestrel 30,000,000 bytes (~28.6 MB) Global, or per request
FormOptions.MultipartBodyLengthLimit Form binding (IFormFile) 134,217,728 bytes (128 MB) Global, or per endpoint with [RequestFormLimits]
IISServerOptions.MaxRequestBodySize IIS in-process hosting 30,000,000 bytes (~28.6 MB) Global
maxAllowedContentLength IIS request filtering (web.config) 30,000,000 bytes (~28.6 MB) Site or application
HttpSysOptions.MaxRequestBodySize HTTP.sys 30,000,000 bytes (~28.6 MB) Global
httpRuntime maxRequestLength Legacy ASP.NET Framework 4096 KB (4 MB) Application

The smallest limit in the chain wins. Kestrel’s and IIS’s 30 MB limits trip first for most files, so that is where to start. The Kestrel, FormOptions, and IIS defaults come from Microsoft’s file uploads and Kestrel options documentation.

An earlier version of this post said IIS has a 4 MB default. That was wrong. The 4 MB figure belongs to the ASP.NET Framework httpRuntime setting, covered in the legacy section below. IIS’s own limit is 30,000,000 bytes.

How do I increase the Kestrel max request body size?

Set it once for the whole app in Program.cs. MaxRequestBodySize is a nullable long, and null removes the limit.

var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel(options =>
{
// 100 MB for every request
options.Limits.MaxRequestBodySize = 100_000_000;
});
var app = builder.Build();

A global limit is the blunt option. A single upload endpoint is usually the only place that needs it, so the per-endpoint attributes below are safer.

How do I set a larger limit for one controller action?

Use [RequestSizeLimit] to set a byte limit, or [DisableRequestSizeLimit] to remove it.

[ApiController, Route("uploads")]
public class UploadController : ControllerBase
{
[HttpPost("big"), RequestSizeLimit(100_000_000)]
public async Task<IActionResult> Big()
{
using var ms = new MemoryStream();
await Request.Body.CopyToAsync(ms);
return Ok(ms.Length);
}
[HttpPost("unlimited"), DisableRequestSizeLimit]
public async Task<IActionResult> Unlimited() => Ok();
}

Both attributes work on a controller class or an action. DisableRequestSizeLimit accepts a body of any size, so pair it with your own checks.

How do I set a larger limit on a minimal API endpoint?

Minimal API endpoints don’t have a dedicated extension method for this. Attach the same attributes as endpoint metadata with WithMetadata:

app.MapPost("/minimal-big", async (HttpRequest request) =>
{
using var ms = new MemoryStream();
await request.Body.CopyToAsync(ms);
return Results.Ok(ms.Length);
}).WithMetadata(new RequestSizeLimitAttribute(100_000_000));
app.MapPost("/minimal-unlimited", async (HttpRequest request) =>
{
using var ms = new MemoryStream();
await request.Body.CopyToAsync(ms);
return Results.Ok(ms.Length);
}).WithMetadata(new DisableRequestSizeLimitAttribute());

How do I change the limit inside middleware?

IHttpMaxRequestBodySizeFeature changes the limit for the current request. This works only before anything reads the body, so check IsReadOnly first.

using Microsoft.AspNetCore.Http.Features;
app.MapPost("/feature", async (HttpContext context) =>
{
var feature = context.Features.Get<IHttpMaxRequestBodySizeFeature>();
if (feature is { IsReadOnly: false })
{
feature.MaxRequestBodySize = 100_000_000; // or null to disable
}
using var ms = new MemoryStream();
await context.Request.Body.CopyToAsync(ms);
return Results.Ok(ms.Length);
});

Once something starts reading the body, setting the limit throws an exception.

How do I raise the multipart form limit for IFormFile?

When you bind IFormFile, FormOptions.MultipartBodyLengthLimit applies on top of the Kestrel limit. Raise both if you accept big files through a form.

using Microsoft.AspNetCore.Http.Features;
builder.Services.Configure<FormOptions>(options =>
{
options.MultipartBodyLengthLimit = 268_435_456; // 256 MB
});

For one endpoint, use [RequestFormLimits(MultipartBodyLengthLimit = ...)], or add a RequestFormLimitsAttribute through WithMetadata. An oversized multipart section throws an InvalidDataException, which surfaces as a 400, not a 413. For a refresher on the form side, see my IFormFile upload example.

How do I fix 413 Payload Too Large or Request Entity Too Large?

A 413 means some layer refused the body size. Work from the outside in:

  1. Reverse proxy. nginx rejects bodies over client_max_body_size (default 1 MB) with 413 Request Entity Too Large. Set client_max_body_size 100m; in the http, server, or location block. Other proxies have their own setting.
  2. IIS. Raise maxAllowedContentLength (next section). IIS usually answers with 404.13, not 413.
  3. Kestrel. Raise MaxRequestBodySize globally or per endpoint, as shown above.
  4. Form binding. Raise MultipartBodyLengthLimit if the error is a 400 from an IFormFile upload.

Kestrel responds with 413 Payload Too Large when the body exceeds its limit. HTTP.sys responds with a generic 500 instead.

How do I increase the limit on IIS?

IIS checks maxAllowedContentLength before the request reaches your app. It’s measured in bytes:

<system.webServer>
<security>
<requestFiltering>
<!-- 100 MB, in bytes -->
<requestLimits maxAllowedContentLength="104857600" />
</requestFiltering>
</security>
</system.webServer>

When ASP.NET Core runs in-process under IIS, IISServerOptions.MaxRequestBodySize also applies (30,000,000 bytes by default). Raising one doesn’t raise the other, so set both:

builder.Services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = 104_857_600;
});

Microsoft’s IIS hosting documentation lists the options.

What about legacy ASP.NET Framework (maxRequestLength)?

This section applies only to ASP.NET Framework (System.Web) apps, not ASP.NET Core. There, httpRuntime controls the limit, and the value is in kilobytes:

<configuration>
<system.web>
<!-- 50 MB, in kilobytes (default is 4096) -->
<httpRuntime targetFramework="4.8" maxRequestLength="51200" executionTimeout="300" />
</system.web>
</configuration>

maxRequestLength defaults to 4096 KB, and exceeding it throws a HttpException. Framework apps need the IIS maxAllowedContentLength change above too. executionTimeout (110 seconds by default) only applies when debug="false", so an upload may work locally in debug and time out in production. See Microsoft’s maxRequestLength reference.

How I verified these limits

I built a scratch net10.0 app with every snippet above, then posted files with curl. With the global Kestrel limit set to 1,000,000 bytes:

Endpoint 0.9 MB 1.5 MB 3 MB 12 MB
Global limit only 200 413 - -
[RequestSizeLimit(5_000_000)] (MVC) 200 200 200 413
WithMetadata(new RequestSizeLimitAttribute(5_000_000)) 200 200 200 413
IHttpMaxRequestBodySizeFeature set to 5,000,000 200 200 200 413
[DisableRequestSizeLimit] / DisableRequestSizeLimitAttribute 200 200 200 200

With Kestrel raised to 50 MB and MultipartBodyLengthLimit at 2,000,000, a 3 MB IFormFile upload returned 400, while a 1.5 MB upload returned 200. Raising the global limit let a 12 MB raw body through.

FAQ

What is the default max file upload size in ASP.NET Core?

Kestrel’s default MaxRequestBodySize is 30,000,000 bytes (about 28.6 MB). Form binding adds a separate 128 MB MultipartBodyLengthLimit, so the smaller Kestrel limit usually rejects a file first.

Why do I still get a 413 after raising MaxRequestBodySize?

Another layer is still enforcing a smaller limit. Check nginx client_max_body_size, IIS maxAllowedContentLength, IISServerOptions.MaxRequestBodySize, and any cloud load balancer or API gateway.

Can I remove the upload limit entirely?

Yes. Set MaxRequestBodySize = null on Kestrel or use [DisableRequestSizeLimit] on an endpoint. Doing it globally invites denial-of-service abuse, so limit it to the endpoints that need it.

Does the limit apply to the whole request or one file?

MaxRequestBodySize covers the entire request body, so a form with several files counts them all together. MultipartBodyLengthLimit applies to each multipart section.

Why does an upload work locally but fail on IIS?

dotnet run uses Kestrel, which has no IIS maxAllowedContentLength check. The IIS limit only appears once the app is hosted in IIS. Test uploads in the same environment you deploy to.

Conclusion

Find the layer that is rejecting the request, then raise only that limit, and only as far as the endpoint needs. Large parallel uploads can overwhelm a server, so pick sizes deliberately. If you’re validating what users send, read my guide on verifying user file uploads. For the multi-file upload UI, see drag and drop upload with ASP.NET Core.

Comments

Related Posts