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>
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).
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.
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.
If you are hosted in IIS, you need two settings:
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With