1

I am trying to upload files that are 6mb in size. The web config is set as follows:

  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="2147483648" />
      </requestFiltering>
    </security>
  </system.webServer>

I keep getting this error : Maximum request length exceeded.

Is there something that I am missing?

Burdy
  • 113
  • 10
  • Does this answer your question? [Maximum request length exceeded.](https://stackoverflow.com/questions/3853767/maximum-request-length-exceeded) – Tawab Wakil Nov 17 '21 at 13:50

3 Answers3

2

In machine.config 4MB is set as default, but you can override it in you web.config file.

Try adding this:

<configuration>  
    <system.web>
       <httpRuntime executionTimeout="240" maxRequestLength="20480" />
    </system.web> 
</configuration>
mike
  • 1,202
  • 1
  • 7
  • 20
  • when adding it to the server an error 505 appears. I don't think this works in my case – Burdy Nov 17 '21 at 13:57
  • Which .net framwork are you targetting? – mike Nov 17 '21 at 14:12
  • @Burdy, have you introduced a syntax error in your config file? Perhaps `system.web` or `httpRuntime` appears twice? You may need to tweak the posted markup to fit your case. – Tawab Wakil Nov 17 '21 at 14:23
  • @mike framework 4.6 – Burdy Nov 17 '21 at 14:45
  • @Burdy Indeed check what Twab Wakil said. Make also sure you are within . You can also add targeted framework : targetFramework="4.6..." I will update my solution . – mike Nov 17 '21 at 15:04
2

Ok so basically I figured that in my case even when editing the webconfig file and its maximum content length, it doesn't really work if you do not set your IIS settings correctly.

To do this:

  1. go on the specific website you want to edit in IIS

  2. select configuration Editor

  3. set the section to - system.web/httpRuntime

  4. set the MaxRequestLength in kilobytes. You can use this tool to make the conversion from kb to mb and vice versa easier https://www.unitconverters.net/data-storage/kb-to-mb.htm

  5. Don't forget to click on apply in the right tab in IIS.

  6. Retry and hope for the best :)

Burdy
  • 113
  • 10
  • Strange that this would work over mike's answer. It's basically doing the same thing, just through a different mechanism. There must have been a typo or some other problem with your file that this approach circumvented. – Tawab Wakil Nov 17 '21 at 16:00
0

Please set 'MaxRequestLength' property in httpRuntime section of web.config to a higher value. Please note that the unit for this property value is KB. The default is 4096 KB = 4 MB

https://learn.microsoft.com/en-us/dotnet/api/system.web.configuration.httpruntimesection.maxrequestlength?view=netframework-4.8

samiksc
  • 167
  • 10