Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

Large uploads fail with HTTP 404.13 on IIS: request filtering, ASP.NET and Kestrel limits stack up

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

Small files upload fine. A larger one fails, and the server answers with:

HTTP 404.13 - Not Found

The request filtering module is configured to deny a request that exceeds the request content length.

Or the connection simply drops partway through. Microsoft documents several size limits that sit in layers between the browser and the application. A request has to fit under every one of them.

What you see

  • HTTP 404.13 on IIS. Microsoft's status code list describes it as Content length too large: the request's Content-Length header is larger than the server allows (Microsoft Learn, HTTP status codes in IIS).
  • In an ASP.NET Core app, a connection error and a reset connection. Microsoft says this probably means the upload is larger than Kestrel's maximum request body size (Microsoft Learn, Upload files in ASP.NET Core).
  • In ASP.NET Core, an InvalidDataException when a form section is larger than the multipart body limit.
  • A file that is just under about 28.6 MB uploads, and a larger one fails. That matches the default limits below.

Why it happens

Each layer has its own limit and its own unit:

Limit Layer Default (Microsoft) Unit
maxAllowedContentLength in <requestLimits> IIS request filtering 30,000,000 (about 28.6 MB) bytes
IISServerOptions.MaxRequestBodySize ASP.NET Core, hosted in-process on IIS 30,000,000 (about 28.6 MB) bytes
KestrelServerOptions.Limits.MaxRequestBodySize ASP.NET Core on Kestrel 30,000,000 (about 28.6 MB) bytes
MultipartBodyLengthLimit (FormOptions) ASP.NET Core form parsing 134,217,728 (128 MB) bytes
maxRequestLength in <httpRuntime> ASP.NET on .NET Framework 4096 (4 MB) kilobytes
maxRequestEntityAllowed in <serverRuntime> IIS server runtime 4294967295 (unlimited) bytes

Sources: Request Limits <requestLimits>, Upload files in ASP.NET Core, HttpRuntimeSection.MaxRequestLength, Server Runtime <serverRuntime>.

The order matters. Microsoft's ASP.NET Core page says IIS checks maxAllowedContentLength before the request reaches the application, and rejects anything over it with 404.13. When an ASP.NET Core app runs in-process on IIS, both the IIS limit and the IISServerOptions limit apply. If the IIS limit is the smaller one, IIS rejects the request first. Microsoft also says the per-action RequestSizeLimit attribute and the per-request IHttpMaxRequestBodySizeFeature change only the ASP.NET Core server limit. They cannot get past maxAllowedContentLength.

How to prove the cause

1. Read the status code and the IIS log. A 404.13 in the response or the site's IIS log means IIS request filtering rejected the upload before the app saw it. Microsoft's status code list says IIS logs are kept under inetpub\logs\Logfiles by default.

2. Compare the failing file size with the limits. If uploads fail just above about 28.6 MB, the defaults above fit. The 28.6 MB pattern does not apply to ASP.NET on .NET Framework. There, uploads fail above 4 MB at the default maxRequestLength, and the error comes from ASP.NET, not as a 404.13 from IIS request filtering.

3. Read the effective <requestLimits>. Check the site's Web.config, and the server level, for <requestLimits maxAllowedContentLength=...>. If it is not set, the default applies. You can also see it in IIS Manager: open Request Filtering for the site, then Edit Feature Settings.

4. Read the application's own limits. For ASP.NET Core, look in Program.cs for IISServerOptions, ConfigureKestrel, FormOptions and any [RequestSizeLimit] or [RequestFormLimits] attributes. For an ASP.NET site on .NET Framework, check <httpRuntime maxRequestLength=...> in Web.config.

5. A reset connection on Kestrel. If there is no 404.13 and the connection resets, Microsoft points to Kestrel's maximum request body size first.

The fix

Raise every limit the upload passes through, to the same target size, in the right unit. Microsoft's ASP.NET Core page says: to support larger uploads on IIS, increase both maxAllowedContentLength in web.config and IISServerOptions.MaxRequestBodySize (or apply RequestSizeLimit).

IIS request filtering, in the site's Web.config (Microsoft's example, 50 MB):

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="52428800" />
    </requestFiltering>
  </security>
</system.webServer>

ASP.NET Core hosted in-process on IIS, in Program.cs:

builder.Services.Configure<IISServerOptions>(options =>
{
    options.MaxRequestBodySize = 52428800; // 50 MB
});

ASP.NET Core on Kestrel, in Program.cs:

builder.WebHost.ConfigureKestrel(options =>
{
    options.Limits.MaxRequestBodySize = 52428800;
});

Or, for a single page or action only, [RequestSizeLimit(52428800)].

Multipart form uploads in ASP.NET Core, if one form part is over 128 MB: raise MultipartBodyLengthLimit in FormOptions, or with [RequestFormLimits] on one page or action. Microsoft's example sets 268435456 (256 MB).

ASP.NET on .NET Framework: raise maxRequestLength. The value is in kilobytes, not bytes. By arithmetic, 50 MB is 51200 KB, while the IIS setting for the same size is 52428800 bytes. Microsoft says the value must be greater than or equal to RequestLengthDiskThreshold, or a configuration error is raised.

Microsoft's examples use 52428800 bytes, which is exactly 50 × 1024 × 1024. Pick the largest file you genuinely need to accept, and use that one size everywhere.

How to confirm the fix

  • A file just under your new limit uploads, and the IIS log shows the request without a 404.13.
  • A file just over the new limit is still rejected. This shows the limit is in force rather than removed.
  • On Kestrel, a large upload completes without a reset connection.

What to watch afterwards

  • Deployments that replace Web.config. If the new file does not carry the <requestLimits> setting, uploads fall back to the default. This follows from the default applying whenever the setting is absent.
  • Other parts of the path. Microsoft notes other Kestrel limits, such as request and response data rates and maximum client connections, may also apply.
  • Memory and disk. Microsoft's server runtime reference notes that letting users upload more content can affect IIS memory. Microsoft's ASP.NET Core page advises benchmarking memory, CPU, disk and database performance for the file sizes you expect.

Risks and limits

  • Do not remove the limits. Microsoft's maxRequestLength reference says that limit can help prevent denial of service from users posting large files. Microsoft's ASP.NET Core page warns that attackers may use uploads for denial of service or to upload malware. Setting MaxRequestBodySize to null removes the ASP.NET Core limit for that request; raise limits to a size you need instead.
  • Two numbers for one case. The <requestLimits> reference says that when request filtering blocks a request over the limit, IIS returns an HTTP 404 to the client and logs the sub-status 413.1 (Content Length Too Large). Microsoft's status code list and ASP.NET Core page describe the 404.13 the client sees. Search the IIS log for both.
  • A 403 instead. If maxRequestEntityAllowed in <serverRuntime> has been lowered from its unlimited default, Microsoft says IIS answers a request over it with an HTTP 403, not a 404.13 (Microsoft Learn, Server Runtime <serverRuntime>).
  • <serverRuntime> also has uploadReadAheadSize, the number of bytes IIS reads into a buffer before passing the request to a module or ISAPI extension. The sources read here do not link it to the 404.13 error, so it is not part of this fix.
  • An ASP.NET Core app that holds each file in a single MemoryStream has its own ceiling. Microsoft advises another approach for files larger than 50 MB.
  • Very large uploads may need a different design, such as uploading in parts, rather than ever-larger limits.

Sources

Next step

An upload must fit under every limit on its path, starting with IIS request filtering: raise each one to the same size, in the right unit. NetLeverage has looked after business servers since 2002. If large uploads still fail, talk to us through managed support with the IIS log line for the failed upload and the size of the file.