Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Error Condition: HttpException: maxRequestLength Exceeded. ASP.NET

0.00/5 (No votes)
13 May 2013 1  
This post explains the cause and solution for the HttpException: maxRequestLength exceeded.

Introduction

While building ASP.NET web applications, we all would have almost certainly used the file upload control. But sometimes, we might encounter an exception message which reads, “System.Web.HttpException: maxRequestLength exceeded”.

The cause of this exception is simple. “maxRequestLength” attribute of the “httpRuntime” tag specifies the maximum size of input files that can be uploaded. By default, the value of this attribute in ASP.NET 4.0 is 4096KB (4 MB).

This value is set in the “machine.config” file which sets the maximum allowable file size for the entire machine as 4MB. This can be easily changed by modifying the “machine.config”. The configuration entry is as follows:

<httpRuntime maxRequestLength=”4096? />

The size is always mentioned in “Kilo Bytes”. If we want the maximum allowable size of files to be say 25MB, then all we need to do is change the value of “maxRequestLength” attribute to 25600.

<httpRuntime maxRequestLength=”25600? />

The above line would allow files up to 25MB to be uploaded. If this entry is added in the machine.config file, then all websites in that machine would allow files up to 25MB to be uploaded. If that entry is added in a particular website’s “web.config” file, then only that website would allow files up to 25MB to be uploaded. Other websites would allow only up to 4MB (default size) files to be uploaded.

One important point to note here is that web.config file entries always take precedence over machine.config file entries. That is, say for example, machine.config file specifies a 25MB file size upload limit, the web.config file of the website can override it.

Just as an addition, the “machine.config” file is located at:

“%SystemRoot%\Microsoft.NET\Framework\Version\Config\machine.config”.

SystemRoot” is the location where Windows is installed. Generally it is “C:\Windows”.

Hope this helps!!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here