From IIS6 maxRequestLength to IIS7 maxAllowedContentLengthFile – specifying maximum file upload size

IIS6 uses the maxRequestLength config setting under the system.web section to specify maximum file upload size with a default of 4 MB.  IIS7 uses the maxAllowedContentLength config setting under the system.webServer section to specify maximum file upload size with a default of 28.6 MB.  This is something to watch out for when migrating your web application from IIS6 to IIS7.  Read on for more information how I found out about this new config setting for IIS7….

I have migrated several sites from IIS6 to IIS7 without much problems.  One gotcha that I did get caught on is the new IIS7 config settings section (system.webServer) and those settings for specifying the maximum file size to be uploaded to the website.  After migrating a certain web application from IIS6 to IIS7 everything appeared fine until a few customers began complaining about issues when uploading files to the website… in particular these were large files around 50MB.

In IIS 6.0 there is a config setting (attribute) called maxRequestLength located under the httpRuntime section in system.web that you can use to specify the maximum allowed request length (in other words the maximum uploaded file size).  In IIS 6.0 the default is 4096 which is number of kilobytes allowed… so a 4MB file is the default file upload size under IIS 6.0. 

A 4MB is pretty small these days so it is quite common to need to override the default and put in a different value here.  For the web application that I was migrating to IIS7, we had increased the maximum file size to 200MB (and told our customers 200MB was the max upload too).  This is what the httpRuntime section was set to:

    <httpRuntime maxRequestLength="204800" executionTimeout="7200"/>

So we migrated the web application to IIS7, tested some large file uploads (we tested with 20MB files… note this for later) and everything seemed great.  After rolling the website out to our customers, a couple weeks post release we got a couple complaints about customers not being able to upload files.  Their files were about 50MB in size.

At first this was puzzling because we clearly had the config setting in place that indicated 200MB was the new limit (or so we thought) AND files larger than 4MB were allowed (we had tested 20MB files).  But we could easily reproduce the customer issue with their 50MB files failing.  So what was going on?

Eventually we tracked it down to IIS7 and the new config section called system.webServer.  We had known that httpHandlers in IIS7 were now to be specified in the system.webServer/handlers section but what we did not know (and did not find out until our customers ran into it) was that the maximum request length setting for IIS7 is also in a new location.  In IIS7 you specify the maximum size of a file to be uploaded to the website by using the maxAllowedContentLength setting (system.webServer/security/requestFiltering/requestLimits >> maxAllowedContentLength).

      <requestLimits maxAllowedContentLength="209715200" ></requestLimits>

Now why didn’t our tests with 20MB files show this?  Because in IIS7 the default value for the maxAllowedContentLength setting is 30000000 and that is in bytes: 30000000 bytes = 28.6 MB.  So in IIS7 the default had increased to 28 MB so we did not notice it since we were testing with only 20 MB files (and assuming the default was 4MB).  In the end we got this resolved fairly quickly and it showed an issue in our testing (we really should have been testing a 200MB file… the limits of what we tell our customers).



  • useful tips, thanks very much

  • Great article. I knew I had to make this change when the time came, but didn't know where the code was. I spent 3 minutes reading your article and made my change. Thanks for saving me tons of research time.

  • Thanks for this post!!!! I was going nuts with an uplaod problem!

  • Great article.
    Thanks a lot.

  • Hello Jeff,

    I used the following under IIS6
    and still having the following exception:
    Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

    Any idea?

  • Hi hh1983,
    You are getting an access denied exception which probably means the IIS application pool identity does not have write access to the location you are trying to write to. Make sure the account has the correct permissions.

  • Thanks a lot ,
    it really helped a lot, i was facing same problem...

    Sandeep Ramani

  • You have to be really careful with this setting on shared hosting platforms. I've had problems with cranking these values up on GoDaddy and other hosting, esp when they cap the memory usage limit for the site or it's an otherwise busy server.

  • Very helpful.

  • one more thing i want know,, once we done the setting in iis 7 , what about the iis 6 setting ,, we need to remove ?

  • Hi,

    I have a sharepoint 2007 app on IIS 6.0 windows server 2003 , and I want to upload files with it using webservice.the app upload file on session and after clicking on sendbtn it send created datatabe to webservice.

    I checked my app with a file with size 9MB and it worked fine, but when I want to upload a 40MB file it returns an error when send file on sendbtn_click

    Exception of type 'System.OutOfMemoryException' was thrown.

    I've set both my sharepoint web confing , so I can upload files on session with no error:

    I did that setting on my webservice too but its not working.

    this app works on my test server very well , but on the customers server its not working.

    I also changed the AspMaxRequestEntityAllowed on Metabase.XML to


    I also changed AspBufferingLimit="41943040"

    and I restarted my iis several times but the problem still exists:(

    please help me


    I should add that my webservice will upload files on sqlserver 2008 R2

  • Hi ashkansiroos,
    The 'System.OutOfMemoryException' indicates a problem with your application most likely trying to load the entire file in memory. It sounds like the file is making it to your server so it is beyond this configuraton setting.

  • Its very Useful for My Issues, thanks

  • thanks a lot, great article

  • great tip, thanks!!

Comments have been disabled for this content.