Link to home
Avatar of Archimel

asked on

ASP.NET upload error: "Maximum request length exceeded."

When I try to upload an image to create a new record in an MVC project, I get server error "Maximum request length exceeded." Attached is the image, and the MVC project I'm referring to can be downloaded from here:

This MVC web app is based on Microsoft's Contoso University series of tutorials. I get the error "Maximum request length exceeded" when I try to upload the attached image to create a new student.

Here are some of the solutions I've found online:
1. Increase upload max size by adding <httpRuntime maxRequestLength="51200" /> to web.config
2. Draw a smaller version of the image using <canvas> and replace the user's chosen image with the canvas image using Javascript
3. Use an API like Google Gears to shrink the image before uploading it

The easiest solution would be to increase maxRequestLength, but it doesn't work. Does anyone know why I can't increase maxRequestLength? Or does anyone know how to implement the the canvas or API solution, or some other solution you may know of?

I'm using Visual Studio 2013 Community.

Thanks in advance.
Avatar of Big Monty
Big Monty
Flag of United States of America image

There are 2 config options you can set, one is maxAllowedContentLength, which is measured in bytes, where maxRequestLength is measured in KB.  Add the following to your Web.config file, so you'll have both parameters defined.

         <requestLimits maxAllowedContentLength="1073741824" />
Avatar of Archimel


<requestLimits maxAllowedContentLength="1073741824" /> didn't work either. Could it be my version of VS? If you were to add maxAllowedContentLength and/or maxRequestLength to web.config in this project, maybe it would work for you? If so, I would know just to uninstall and reinstall my VS.

try this

      <httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="15360" requestLengthDiskThreshold="15360" executionTimeout="400"/>
Please try below in your web.config:
        <httpRuntime maxRequestLength="1048576" executionTimeout="3600" useFullyQualifiedRedirectUrl="false"  appRequestQueueLimit="4000"/>
         <requestLimits maxAllowedContentLength="1073741824"  />

Open in new window

Avatar of Archimel

Blurred text
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
When I took out the <httpRuntime targetFramework="4.5" /> and inserted everyone's suggestions, they all worked. I assume it's because there can't be two <httpRuntime> tags in <system.web>.

You should know that web.config contains unique settings, and HTTPRUNTIME must include one time only and it will work for every request you send to IIS.

AND by including our solution, if it is working, then you should appreciate our efforts!
Replacing the original <httpRuntime> tag resolved the issue.