Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maxRequestLength for .Net 4.5.1 framework

Tags:

asp.net-mvc

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>

like image 483
mgsdew Avatar asked Apr 27 '14 18:04

mgsdew


People also ask

What is the max maxRequestLength?

HttpRuntime maxRequestLength Use the maxRequestLength of the httpRuntime element. The default size is 4096 kilobytes (4 MB). Max value 2,147,483,647 kilobytes (~82 Terabyte).

What is maxRequestLength?

The MaxRequestLength property specifies the limit for the buffering threshold of the input stream. For example, this limit can be used to prevent denial of service attacks that are caused by users who post large files to the server.

What is maxAllowedContentLength in web config?

The maxRequestLength indicates the maximum file upload size supported by ASP.NET, the maxAllowedContentLength specifies the maximum length of content in a request supported by IIS.


1 Answers

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:

  • http://forums.iis.net/t/1169846.aspx
  • Which gets priority, maxRequestLength or maxAllowedContentLength?
like image 55
Yorro Avatar answered Sep 28 '22 11:09

Yorro