Tuesday, 24 March 2009

System.Web.HttpException: Maximum request length exceeded

This problem occurs because the default value for the maxRequestLength parameter in the section of the Machine.config file is 4096 (4 megabytes). As a result, files that are larger than this value are not uploaded by default.
This will also affect exports if you are extracting to excel say or in fact any attachment type if the file is larger than the default it will fail.

In the Machine.config file, change the maxRequestLength attribute of the

configuration section to a larger value. This change affects the whole computer.

the second option if you don't want to change the value for the server you can change it on one site by modifiying the Web.config file, this will override the value of maxRequestLength for the application.

For example, the following entry in Web.config allows files that are less than or equal to 8 megabytes (MB) to be uploaded < httpRuntime maxRequestLength="8192" />

the max is 1Gb or 1048578 in .NET 1.0 and 1.1 the limit in .NET 2.0 is 2GB 2097151 I've not had reason to test .NET 3.0 but i'm sure it will be even larger.

Just insert the line after the system.web on the web.config file of the site you want to allow the larger files.

< system.web>

< httpRuntime maxRequestLength="1048576" />

< /system.web>

Then restart the site, note the site you don't need to restart all of the IIS to make this work.