ASP.NET Maximum request length exceeded

[From]: http://stackoverflow.com/questions/3853767/maximum-request-length-exceeded

If you are using IIS for hosting your application, then the default upload file size if 4MB. To increase it, please use this below section in your web.config –

  <configuration>
    <system.web>
      <httpRuntime maxRequestLength="1048576" />
    </system.web>
  </configuration>

For IIS7 and above, you also need to add the lines below:

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

Note: maxAllowedContentLength is measured in bytes while maxRequestLength is measured in kilobytes, which is why the values differ in this config example. (Both are equivalent to 1 GB.)

shareedit

I don’t think it’s been mentioned here, but to get this working, I had to supply both of these values in the web.config:

In system.web

  <httpRuntime maxRequestLength="1048576" executionTimeout="3600" />

And in system.webServer

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

IMPORTANT : Both of these values must match. In this case, my max upload is 1024 megabytes.

maxRequestLength has 1048576 KILOBYTES, and maxAllowedContentLength has 1073741824 BYTES.

I know it’s obvious, but it’s easy to overlook.

shareedit
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s