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:

http://www.mikesdotnetting.com/article/259/asp-net-mvc-5-with-ef-6-working-with-files

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.
ArchimelAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontyWeb Ninja at largeCommented:
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.

 <system.webServer>
   <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
   </security>
 </system.webServer>
ArchimelAuthor Commented:
<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.
Kamal KhaleefaInformation Security SpecialistCommented:
hi

try this

      <httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="15360" requestLengthDiskThreshold="15360" executionTimeout="400"/>
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Prakash SamariyaIT ProfessionalCommented:
Please try below in your web.config:
<configuration>
    <system.web>
        <httpRuntime maxRequestLength="1048576" executionTimeout="3600" useFullyQualifiedRedirectUrl="false"  appRequestQueueLimit="4000"/>
    </system.web>
</configuration>
....
<system.webServer>
   <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="1073741824"  />
      </requestFiltering>
   </security>
 </system.webServer>

Open in new window

ArchimelAuthor Commented:
I figured out the problem. In the Web.config file, there's this code:

 <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <httpModules>
    </httpModules>
  </system.web>

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>.

Thank you all for your help. This issue has been resolved.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Prakash SamariyaIT ProfessionalCommented:
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!
ArchimelAuthor Commented:
Replacing the original <httpRuntime> tag resolved the issue.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.