Tips for Uploading and Staging Large Files


This article summarizes tips and tricks for uploading and staging large files such as attachments, videos, media files, etc.

Uploading files larger than a few MB to your Kentico instance can be a bit tricky. The default maximum file size may not be sufficient for your requirements—the limitation is there to prevent denial of service attacks in which an attacker submits a lot of huge files, which can overwhelm the web server. In a case like this, you might be getting “HTTP status 404: Not Found” errors when uploading files, which can be misleading as that is not really the root cause of the problem.

You can adjust the limits of the request by changing the following values in your web.config:

  • maxRequestLength (<httpRuntime> element under <system.web>): stores the value in Int32 and is in KiloBytes. The default is 4096 KB (approx. 4MB), max. value is 2097151 KB (approx. 2GB)
  • maxAllowedContentLength (<security>/<requestFiltering>/<requestLimits> element under <system.webServer>): stores value in uint and is in bytes. The default value is 30000000 B (approx. 28.6MB), max. value is 4294967295 B (approx. 4GB)

Example (using the max possible values):

<system.web> <httpRuntime maxRequestLength="2097151" waitChangeNotification="1" maxWaitChangeNotification="3600" requestValidationMode="2.0" maxUrlLength="1000"/> </system.web> <system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="4294967295" /> </requestFiltering> </security> </system.webServer>

Please note: that there is also a WebDAV configuration section in the web.config (sample screen shot) that only affects files uploaded through WebDAV, so make sure you are not making the mentioned changes there!

Since the maximum request size limit is there to protect your site, the best practice is to expand the file-size limit for specific directories rather than the entire application. That is possible if you use the <location> tag in your web.config file to achieve it, for example, restricting it to staging files only:

<location path="CMSPages/Staging">     <system.web>         <httpRuntime executionTimeout="2400" maxRequestLength="2147483647" />     </system.web>     <system.webServer>         <security>             <requestFiltering>               <requestLimits maxAllowedContentLength="4294967295" />             </requestFiltering>         </security>     </system.webServer> </location>

For more information, please see the documentation—Staging large files.

Share this article on   LinkedIn

Filip Ligač

Hi, I work as a Cloud Support Specialist here at Kentico. I write about Microsoft Azure and and am trying to extend knowledge about the best practices for deployment.