I am getting the error Maximum request length exceeded when I am trying to upload a video in my site.

How do I fix this?

14 Answers 11

The maximum request size is, by default, 4mb (4096 KB)

This is explained here: http://support.microsoft.com/default.aspx?scid=kb;EN-US;295626

The above article also explains how to fix this issue :)

4 upvote
  flag
The link is redirecting me to the microsoft support homepage – Bishop
upvote
  flag
Maybe something was wrong. The link redirects here – gofr1
up vote 1519 down vote accepted

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

7 upvote
  flag
Thank you sachin and i added some thing like <httpRuntime maxRequestLength="32768" executionTimeout="180" /> – Surya sasidhar
upvote
  flag
@Surya- The length is in kbytes. So you can set any size as you want in MaxRequestLength. My example sets the size to 1gb, yours is 32MB – Sachin Shanbhag
11 upvote
  flag
maxAllowedContentLength must be in bytes, not kilobytes, so the examples provided are not equivalent. – Matt Sharpe
29 upvote
  flag
With both IIS 7.5 and VS RC 2012 IIS Express I had to set BOTH of these. The httpRuntime one configures ASP.NET's max length while requestLimits configures IIS's max length, //allinonescript.com/questions/6327452/… and forums.iis.net/t/1169846.aspx – Despertar
17 upvote
  flag
It's worth pointing out, again, that the maxAllowedContentLength is in bytes, not kilobytes. The two values should not be the same number, because they are not the same measurement unit. – Pandincus
10 upvote
  flag
Make sure that you're adding this setting to the main Web.config instead of the one inside the Views folder – Serj Sagan
upvote
  flag
i have iis 8, i did what you said, but still not exceeded, any solution for iis 8 ? – Tarek
upvote
  flag
@AmbiguousTk - As far as I know, it should be same settings for IIS8 too. what is the limit you are trying to set? Seems the max upload limit you can set is upto 2GB. – Sachin Shanbhag
upvote
  flag
@SachinShanbhag i set it to 1000000000 byte which means 953 mb, and i restarted the web site, yet the error is showing up... – Tarek
2 upvote
  flag
@SachinShanbhag Please include IMPORTANT: Both of these values must match. In this case, my max upload is 1024 megabytes. from Karls answer to make this right, then it works. – Don Thomas Boyle
1 upvote
  flag
Your calculations are in Kibibytes and Gibibyte, time to update the answer? Hehe. – Rosdi Kasim
upvote
  flag
@SachinShanbhag any idea how to implement this on java? //allinonescript.com/questions/31914474/… – Ondrej Tokar
upvote
  flag
Be careful that in your web config file this node may be already have so you just add additional attribute only then.Just copy and past wont work since it already define the attribute then trow a error. – Prageeth
upvote
  flag
I have multiple Web.config files in my project - do they all need these entries? – B. Clay Shannon
upvote
  flag
KB MB GB Conversion Calculator: whatsabyte.com/P1/byteconverter.htm – Moji
1 upvote
  flag
@B.ClayShannon add it to the root web.config file. – yogihosting
upvote
  flag
@tarek try adding executionTimeout="3600" to httpRuntime and see if this solves your problem. – yogihosting
upvote
  flag
Shoud I increase uploadReadAheadSize as well? – mtkachenko
upvote
  flag
In my case the Root web.config file was located under \Windows\Microsoft.NET\Framework\v4.0.30319\Config\ – 0014
upvote
  flag
When I do this I receive an error saying my config file couldn't be read. HTTP Error 500.19 sites the line I add as being the source of the error. Is there something else I need to do? – Brad
upvote
  flag
Worked like a charm, thank you! – Thomas Fonseca

There's an element in web.config to configure the max size of the uploaded file:

<httpRuntime 
    maxRequestLength="1048576"
  />

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.

3 upvote
  flag
To any it may concern: This answer also works perfectly for IIS-Express (asp.net-webpages with WebMatrix) – VoidKing
4 upvote
  flag
Yes, this is answer that worked for me instead of Sachin's answer. It works on Azure too. – Gautam Jain
4 upvote
  flag
This is definitely the correct answer... both entries must be present. In case of MVC 3, it can be in the project root web.config file. – Miguel Angelo
2 upvote
  flag
another important thing is the 'executionTimeout' which Karl mentions – Muhammad Amin
21 upvote
  flag
I had to combine this with an existing line for: <httpRuntime targetFramework="4.5" maxRequestLength="1048576" executionTimeout="3600" /> – Ken Mc
upvote
  flag
@SachinShanbhag's answer does indicate that both maxAllowedContentLength and maxRequestLength are required for IIS7. For IIS6 maxAllowedContentLength is not used. – Cyberherbalist
1 upvote
  flag
To all the people who are new to ASP.NET there is a web.config file and a web.Debug.config file. The edits need to go into the Web.Config file, not the web.Debug.config file. – Darren Hoehna
upvote
  flag
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" /> This cause error in iis express 10 and targetFramework="4.5.2" But when combine with <httpRuntime targetFramework="4.5.2" maxRequestLength="1048576" executionTimeout="3600" /> Works correctly – ramin_rp
upvote
  flag
I have multiple Web.config files in my project - do they all need to have these entries added? – B. Clay Shannon
upvote
  flag
I guess with with more the upload size, the timeout should be adjusted so that the request doesn't terminate when the upload is in progress. – Soundararajan
upvote
  flag
@B.ClayShannon add this in the root web.config file. – yogihosting
upvote
  flag
executionTimeout="3600" is that means 1 hour? – toha

It may be worth noting that you may want to limit this change to the URL you expect to be used for the upload rather then your entire site.

<location path="Documents/Upload">
  <system.web>
    <!-- 50MB in kilobytes, default is 4096 or 4MB-->
    <httpRuntime maxRequestLength="51200" />
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
        <!-- 50MB in bytes, default is 30000000 or approx. 28.6102 Mb-->
        <requestLimits maxAllowedContentLength="52428800" /> 
      </requestFiltering>
    </security>
  </system.webServer>
</location>
upvote
  flag
Nice Solution thinking about the location. But is there a location path when working with MVC (and therefore working with routes)? – Luuk Krijnen
1 upvote
  flag
It would be a URL corresponding to the route that you have your upload action set to. In my case, I have a Documents controller with an action called Upload that I post the form to. In your case it would be whatever the url to your action would be. – Nick Albrecht
upvote
  flag
For anyone who likes this answer, see this. – DontVoteMeDown
upvote
  flag
@NickAlbrecht, Is this working for web APIs? – Allan Chua
upvote
  flag
I have not tested it with WebAPI but I have no reason to think it wouldn't work with it – Nick Albrecht
upvote
  flag
Dude you rock. Sorry, but my tiny little up vote wasn't enough. – Nicholas Petersen

Please check this code demurrer to solve your problem.. copy it, it is a web.config file. .

<system.web>
     <httpRuntime executionTimeout="3600" maxRequestLength="102400" requestLengthDiskThreshold="80" useFullyQualifiedRedirectUrl="false"
     minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100" enableKernelOutputCache="true" enableVersionHeader="true"
     requireRootedSaveAsPath="true" enable="true" shutdownTimeout="90" delayNotificationTimeout="5" waitChangeNotification="0"
     maxWaitChangeNotification="0" enableHeaderChecking="true" sendCacheControlHeader="true" apartmentThreading="false" />
<system.web>
27 upvote
  flag
This contains a boatload of stuff irrelevant to the original question. – georgiosd
4 upvote
  flag
Not focused to solve the OP question. – DanielV

And just in case someone's looking for a way to handle this exception and show a meaningful explanation to the user (something like "You're uploading a file that is too big"):

//Global.asax
private void Application_Error(object sender, EventArgs e)
{
    var ex = Server.GetLastError();
    var httpException = ex as HttpException ?? ex.InnerException as HttpException;
    if(httpException == null) return;

    if(httpException.WebEventCode == WebEventCodes.RuntimeErrorPostTooLarge)
    {
        //handle the error
        Response.Write("Too big a file, dude"); //for example
    }
}

(ASP.NET 4 or later required)

upvote
  flag
maxAllowedContentLength should be higher than (maxRequestLength * 1024) for the exception generation. – Der_Meister

If you have a request going to an application in the site, make sure you set maxRequestLength in the root web.config. The maxRequestLength in the applications's web.config appears to be ignored.

upvote
  flag
If I could upvote this more than once I would. This wasted a day of my life. If you have a virtual dir sub-application, you have to put the httpRuntime maxRequestLength="### and requestLimits maxAllowedContentLength in a web config at the root level, not at the sub-app level. – nickvans

maxRequestLength (length in KB) Here as ex. I took 1024 (1MB) maxAllowedContentLength (length in Bytes) should be same as your maxRequestLength (1048576 bytes = 1MB).

<system.web>
   <httpRuntime maxRequestLength="1024"
             executionTimeout="3600" />
   <compilation debug="true"/>
</system.web>

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

It bothered me for days too. I modified the Web.config file but it didn't work. It turned out that there are two Web.config file in my project, and I should modified the one in the ROOT directory, not the others. Hope this would be helpful.

I can add to config web uncompiled

<system.web> 
  <httpRuntime maxRequestLength="1024" executionTimeout="3600" /> 
  <compilation debug="true"/> 
</system.web> 
<security> 
  <requestFiltering> 
    <requestLimits maxAllowedContentLength="1048576"/> 
  </requestFiltering> 
</security>
upvote
  flag
The executionTimeout attribute has nothing to do with what is asked, and neither does the compilation tag. – Mathias Lykkegaard Lorenzen

I was tripped up by the fact that our web.config file has multiple system.web sections: it worked when I added < httpRuntime maxRequestLength="1048576" /> to the system.web section that at the configuration level.

I had to edit the C:\Windows\System32\inetsrv\config\applicationHost.config file and add <requestLimits maxAllowedContentLength="1073741824" /> to the end of the...

<configuration>
    <system.webServer>
        <security>
            <requestFiltering>

section.

As per This Microsoft Support Article

If you can't update configuration files but control in full the code that handles uploaded files use HttpContext.Current.Request.GetBufferlessInputStream(true).

The true value for disableMaxRequestLength parameter tells the framework to ignore configured request limits.

For detailed description visit https://msdn.microsoft.com/en-us/library/hh195568(v=vs.110).aspx

Not the answer you're looking for? Browse other questions tagged or ask your own question.