How to set the maxAllowedContentLength to 500MB while running on IIS7?

asp.netIis 7File Upload.Net 4.0

asp.net Problem Overview


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

http://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?

asp.net Solutions


Solution 1 - asp.net

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

First

  • Web.Config/system.web/httpRuntime/maxRequestLength
  • Unit of measurement: kilobytes
  • Default value 4096 KB (4 MB)
  • Max. value 2147483647 KB (2 TB)

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>

Solution 2 - asp.net

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

So it should work fine.

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

See also: https://stackoverflow.com/questions/3853767/maximum-request-length-exceeded/ [1]: http://msdn.microsoft.com/en-us/library/ms689462%28VS.90%29.aspx [2]: http://msdn.microsoft.com/en-us/library/x0sksh43.aspx [3]: http://www.iis.net/ConfigReference/system.webServer/security/requestFiltering/requestLimits

Solution 3 - asp.net

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.MaxValue4294967295 bytes : ~4GB

Max for maxRequestLength is: Int32.MaxValue2147483647 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>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAmr ElgarhyView Question on Stackoverflow
Solution 1 - asp.netAnderson RissardiView Answer on Stackoverflow
Solution 2 - asp.netabatishchevView Answer on Stackoverflow
Solution 3 - asp.netLegendsView Answer on Stackoverflow