/ asp.net

Uploading more than 28MB in ASP.NET MVC5

If you have been building a website with ASP.NET MVC and you need to upload files, you might have had issues either once or twice. For me it happened twice. If you haven't had issues yet, most likely they are coming soon, that is of course if you will have users uploading huge files.

The first problem I hit was uploading a file greater than 4MB. If the site is for your selfies and funny cat videos, you won't need this.

To lift the limit, go to your Web.config file and inside the system.web section add the line

<httpRuntime targetFramework="4.5"
   maxRequestLength="1048576"
   requestLengthDiskThreshold="1048576"
   executionTimeout="1200" /><!--set to 1GB-->

This is how mine looks like:

image 1

The 28.8MB limit stil exists. Why? because there is another limitation in IIS7. The solution is still within the same web.config file, but now you will be configuring your hosting server side, not your application. If you have your own server like a VM you can change the setting in the IIS7 configuration options (google for details). Unfortuantely, this is not the case for most people. You will need to add this line in your system.webServer section

<security>
   <requestFiltering>
      <requestLimits maxAllowedContentLength="1073741824"/><!--set to 1GB -->
   </requestFiltering>
</security>

With these setting you will be done.