Cry about...
MS-Windows Troubleshooting


Server Error in '/www' Application ... Maximum request length exceeded.


Symptom:

When trying to run a .NET web-application, when a user posts back from a page the following error is generated in the browser:

Server Error in '/www' Application
Maximum request length exceeded.

Also, in the event log the following error is generated:

Source: ASP.NET 2.0.50727.0
Category: Web Event
Type: Warning
Event ID: 1309

Event code: 3004
Event message: Post size exceeded allowed limits
.
.
.

Cause

The server limits the size of post data - this is the data posted back from the browser when the visitor submits the form, and it includes the data on the form together with any viewstate information, cookies and a few other bits and bobs. The limit exists to hinder denial of service attacks which might otherwise use your bandwidth by posting infinite streams of data to your server.

The default limit for postback data is 4MB, which is sufficiently large that many developers are never aware of the limit.

Remedy:

  • You can increase the limit. The limit is set in the web.config file, in the httpRuntime element. The httpRuntime element should be within system.web which in turn is within configuration. The httpRuntime element has the attribute maxRequestLength, which specifies the maximum size of the posted data. It is specified in KB and the default is 4096KB (4MB). Perhaps consider doubling the value.

    For example, setting it to 8192KB (8MB):

    <configuration>
      .
      .
    <system.web> <httpRuntime maxRequestLength="8192"/> . . </system.web> </configuration>
  • Avoid the problem by reducing the amount of data being posted back. It is worth considering that the default of 4MB is in most cases quite generous. Whilst in some cases this limit is restrictive, do consider the length of time it takes to post back 4MB of data. This is data that needs be transmitted from the browser back to the server. 4MB on a good broadband connection may represent only a couple of seconds, but on a dial up connection the request will probably timeout before the default limit is ever reached. So do review what data is being posted back and whether it can be reduced. For example, how large is the viewstate and if its large then consider whether everything needs to have viewstate enabled?

These notes have been tested within Microsoft Visual Studio .NET 2008 running under Windows Vista, and on a target server running Windows 2003 Web Edition, and may apply to other versions as well.



About the author: is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.