0

I am working on an MVC5 project that allows users to upload files. I already have methods to filter out invalid file extensions (only pictures and pdfs are allowed). However, when I try to upload a large file, regardless of extension, I get this error:

HTTP Error 404.13 - Not Found
The request filtering module is configured to deny a request that exceeds
the request content length.

The method to upload doesn't even get called, it just goes straight to the error page.

One post I found expressed that I needed to modify my project's web.config file, and I did as such:

 <security>
  <requestFiltering>
    <requestLimits maxAllowedContentLength="6000000" />
  </requestFiltering>
</security>

I still get the error, so I also tried adding <httpRuntime maxRequestLength="6000" executionTimeout="3600" /> to <system.web>, but that threw this error:

HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data 
for the page is invalid.

Obviously this line must be for earlier versions of IIS.

I also found another solution that suggested editing the applicationHost.config file on my server like the project's web.config; this also did nothing.

Any suggestions?

Anders
  • 12,088
  • 34
  • 98
  • 146

1 Answers1

1

It looks like you actually made the maxAllowedContentLength smaller. The default is 30000000 bytes and you have 6000000 bytes above.

30000000 b = 30 mb

6000000 b = 6 mb

Adding another 0 should do the trick.

Aaron
  • 1,361
  • 1
  • 13
  • 30
  • As users will be uploading images and/or pdfs, I want to restrict files to a maximum of 6mb (which is pretty generous for an image, anyway).The 'issue' is if a larger file is submitted, my controller method does not even get hit; the site just goes to the IIS error page. – Anders Dec 05 '14 at 21:09
  • 1
    The controller won't get called. The framework has fired off those errors protecting the controller. You will have to trap that in Global.asax.cs application_error – phillip Dec 05 '14 at 21:15
  • That is expected because IIS is throwing the error before it process the request/gets to your controller. I would say increase the size in the web.config file so IIS won't throw an error and validate the file size some other way. – Aaron Dec 05 '14 at 21:16
  • 1
    Maybe this: http://stackoverflow.com/questions/10445861/validating-for-large-files-upon-upload – Aaron Dec 05 '14 at 21:17
  • @phillip thanks for that explanation. I figured that was probably why I couldn't do anything. – Anders Dec 05 '14 at 21:18
  • 1
    @Aaron I am surprised my hours of searching didn't pull this post up...thanks! – Anders Dec 05 '14 at 21:19
  • So just for kicks I added an additional zero to the contentLength, allowing ~28MB file. I still get an error page when using a test 5.5MB file, but this time it is an ASP.NET error page not an IIS error page. Weird! – Anders Dec 05 '14 at 21:23