Click here to Skip to main content
15,888,351 members
Articles / Web Development / ASP.NET

Error Condition: HttpException: maxRequestLength Exceeded. ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.00/5 (2 votes)
13 May 2013CPOL1 min read 13.4K   4   2
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:

HTML
<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.

HTML
<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.

<quote>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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 3 Pin
Jasmine250113-May-13 8:05
Jasmine250113-May-13 8:05 
GeneralRe: My vote of 3 Pin
Amogh Natu13-May-13 20:13
professionalAmogh Natu13-May-13 20:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.