maxRequestLength for .Net 4.5.1 framework

16

I want to convert a .Net framework 4.0 code into .Net framework 4.5. This is basically a file upload related code. Now I face some problems. What is the maximum value of maxRequestLength? I already add this line in my web.config file but it does not work and the Error code is 0x800700b7

<system.web>
<httpRuntime maxRequestLength="102400" executionTimeout ="3600" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2880"/>
</authentication>
<pages>
  <namespaces>
    <add namespace="System.Web.Helpers"/>
    <add namespace="System.Web.Mvc"/>
    <add namespace="System.Web.Mvc.Ajax"/>
    <add namespace="System.Web.Mvc.Html"/>
    <add namespace="System.Web.Optimization"/>
    <add namespace="System.Web.Routing"/>
    <add namespace="System.Web.WebPages"/>
  </namespaces>
  </pages>
  <compilation debug="true"/>
  </system.web>
  <system.webServer>
  <validation validateIntegratedModeConfiguration="false"/>

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

<handlers>
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"/>
  <remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." />
</handlers>

asp.net-mvc
asked on Stack Overflow Apr 27, 2014 by mgsdew • edited Oct 6, 2014 by Dairo

1 Answer

21

If you are hosted in IIS, you need two settings:

  • maxRequestLength - for ASP.net (measured in KB)
  • maxAllowedContentLength - for IIS (measured in Bytes)

Sample config: (this is for 100MB upload limit)

<configuration>  
    <system.web>  
        <httpRuntime maxRequestLength="102400" executionTimeout="3600" />  
    </system.web>  
</configuration>
<system.webServer>  
   <security>  
      <requestFiltering>  
         <requestLimits maxAllowedContentLength="104857600" />  
      </requestFiltering>  
   </security>  
 </system.webServer>  

The smaller of the two will take precedence. For IIS, the default is 4MB.

Error handling

Both throws different exceptions.

  • maxRequestLength - Whenever a file exceeds this setting, you'll get an Application_Error (standard ASP error)
  • maxAllowedContentLength - Whenever a file exceeds this setting, you'll get IIS error.

The IIS error is harder to debug, so it is advisable that you set the maxAllowedContentLength larger. maxRequestLength is easier to catch since its at application level.

Sources:

answered on Stack Overflow Apr 28, 2014 by Yorro • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0