Multipart Form Data 404 on file too large

I stumbled about a strange behaviour on ASP.NET MVC REST API. I send an HTTP request using PostMan with a large file (form-data). Basically it's not an ASP.NET issue, the issue is IIS.
The error you will see is really strange and doesn't have any hints about the real issue. You will get an HTTP 404 Error Code as response with the following text in the body: The resource you are looking for has been removed, had it's name changed, or is temporarily unavailable. It basically looks like a standard 404.

The real issue is that the file in the from-data field is too large. To make it more clear: The request and/or content length is too large.

To fix this you have to change 1 or 2 things.

  1. maxRequestLength (in megabyte): Set this to your desired request length.
  2. maxAllowedContentLength (in byte): If you want to allow content lengths greater then 30MB, you need to modify this setting, too.

Here is an example which sets both settings to approx 100MB:

<system.web>
    <compilation debug="true" targetFramework="4.6.1" />
    <httpRuntime targetFramework="4.6.1" maxRequestLength="102400" />
  </system.web>
  <system.webServer>
      <security>
          <requestFiltering>
              <requestLimits maxAllowedContentLength="104857600"/>
          </requestFiltering>
      </security>
    <httpProtocol>
   </system.webServer>

The 404 behaviour is documented here: https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/requestfiltering/requestlimits/


comments powered by Disqus