118

I changed the maxAllowedContentLength to

<security>
    <requestFiltering>
        <requestLimits maxAllowedContentLength="5024000000" />
    </requestFiltering>
</security>

In my web.config, but when running on IIS7 I get this error:

The 'maxAllowedContentLength' attribute is invalid. Not a valid unsigned integer

https://i.stack.imgur.com/u1ZFe.jpg

but when I run in the VS server it run normally without any errors.

How to config my website to allow upload files with 500MB size, without this problem on IIS7?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Amr Elgarhy
  • 66,568
  • 69
  • 184
  • 301
  • 2
    5024000000 (let me add thousand separators) 5.024.000.000 is larger than the maximum unsigned int 4.294.967.295, you are looking for 502.400.000 as the value in ur config instead (without the thousand separators) – Lennart Nov 07 '19 at 09:12

3 Answers3

199

The limit of requests in .Net can be configured from two properties together:

First

  • Web.Config/system.web/httpRuntime/maxRequestLength (in kilobytes)
  • Unit of measurement: kilobytes
  • Default value 4096 KB (4 MB)
  • Max. value 2147483647 KB (2 TB; older IIS may be limited to 2097151 KB, aka around 2 GB)

Second

  • Web.Config/system.webServer/security/requestFiltering/requestLimits/maxAllowedContentLength (in bytes)
  • Unit of measurement: bytes
  • Default value 30000000 bytes (28.6 MB)
  • Max. value 4294967295 bytes (4 GB)

References:

Example:

<location path="upl">
   <system.web>
     <!--The default size is 4096 kilobytes (4 MB). MaxValue is 2147483647 KB (2 TB)-->
     <!-- 100 MB in kilobytes -->
     <httpRuntime maxRequestLength="102400" />
   </system.web>
   <system.webServer>
     <security>
       <requestFiltering>          
         <!--The default size is 30000000 bytes (28.6 MB). MaxValue is 4294967295 bytes (4 GB)-->
         <!-- 100 MB in bytes -->
         <requestLimits maxAllowedContentLength="104857600" />
       </requestFiltering>
     </security>
   </system.webServer>
 </location>
Frédéric
  • 9,364
  • 3
  • 62
  • 112
Anderson Rissardi
  • 2,377
  • 1
  • 16
  • 21
  • 8
    Very helpful, however I believe that the max value for maxAllowedContentLength is roughly 4 GB, not 4 TB – Snicklefritz Jan 12 '17 at 00:01
  • The article says "Specifies the maximum length of content in a request, in bytes.". Means both config keys use BYTES making max request size same, 4GB. – abatishchev Oct 13 '19 at 19:27
  • @abatishchev The other config key, the httpRuntime maxRequestLength one, is specified in kilobytes, not bytes. The requestLimits maxAllowContentLength one is specified in just bytes. – clamum Nov 10 '22 at 21:31
  • This worked for me. Thank you. – Eccaos Aug 09 '23 at 17:08
105

According to MSDN maxAllowedContentLength has type uint, its maximum value is 4,294,967,295 bytes = 3,99 gb

So it should work fine.

See also Request Limits article. Does IIS return one of these errors when the appropriate section is not configured at all?

See also: Maximum request length exceeded

Community
  • 1
  • 1
abatishchev
  • 98,240
  • 88
  • 296
  • 433
20

IIS v10 (but this should be the same also for IIS 7.x)

Quick addition for people which are looking for respective max values

Max for maxAllowedContentLength is: UInt32.MaxValue 4294967295 bytes : ~4GB

Max for maxRequestLength is: Int32.MaxValue 2147483647 bytes : ~2GB

web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <!-- ~ 2GB -->
    <httpRuntime maxRequestLength="2147483647" />
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
        <!-- ~ 4GB -->
        <requestLimits maxAllowedContentLength="4294967295" />
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>
Legends
  • 21,202
  • 16
  • 97
  • 123
  • Changing "httpRuntime maxRequestLength" is not a good practice (DoS), you need to change is "requestLimits maxAllowedContentLength" [configuring aspnet and iis request length for post data](https://weblog.west-wind.com/posts/2016/apr/06/configuring-aspnet-and-iis-request-length-for-post-data) – Javier Cañon Dec 17 '20 at 17:47
  • 1
    -1 for incorrectly usng maxRequestLength. It is specifid in kilobytes, see https://learn.microsoft.com/en-us/dotnet/api/system.web.configuration.httpruntimesection.maxrequestlength?view=netframework-4.8 – balintn Jul 18 '21 at 18:12