IIS7 and large files

Author: Andrei Komarov
Posted: 11/30/2007 10:26:32 AM

Problem: How can I upload large files to the media library on IIS7?

Answer: By default in IIS 7 requestFiltering has the MaxAllowedContentLength property enabled. It specifies, in bytes, the maximum length of the content in a request. The default is 30,000,000 (approximately 30 megabytes.) To change this value you must include the following code in your web.config file if you want to apply this setting to your application. If you want to change this setting for all of the computer and not just this ASP.NET application, you must modify the Machine.config file. By default, the element is set to the following parameters in the Machine.config file: The Machine.config file is located in the \System Root\Microsoft.NET\Framework\Version Number\CONFIG directory.

<configuration>

        <system.webServer>

            <security>

                <requestFiltering>

                    <requestLimits maxAllowedContentLength="100000000"/>

                </requestFiltering>

            </security>

        </system.webServer>

</configuration>

If you get an error that requestFiltering cannot be overridden you must edit applicationHost.config.

Edit %windir%\System32\inetsrv\config\applicationHost.config.

To allow separate applications to define their own deviations from the safety configuration, replace:

< section name = "requestFiltering" overrideModeDefault = "Deny" />

With:

< section name = "requestFiltering" overrideModeDefault = "Allow" /> 

Note: the following settings should be corrected accordingly.

  1.       <!--  MEDIA - MAX SIZE IN DATABASE

                The maximum allowed size of media intended to be stored in a database (base64 blob).

                This value must be less than the ASP.NET httpRuntime.maxRequestLength setting.

                Default value: 20MB

          -->

          <setting name="Media.MaxSizeInDatabase" value="20MB" />

     

  2.       <!--  MEDIA - MAX SIZE IN MEMORY

                The maximum size of media to load into memory for processing (rezising etc.).

                Default value: 40MB

          -->

          <setting name="Media.MaxSizeInMemory" value="40MB" />

     

  3.       <!--

          httpRuntime Attributes:

            executionTimeout="[seconds]" - time in seconds before request is automatically timed out

            maxRequestLength="[KBytes]" - KBytes size of maximum request length to accept

            useFullyQualifiedRedirectUrl="[true|false]" - Fully qualifiy the URL for client redirects

            minFreeThreads="[count]" - minimum number of free thread to allow execution of new requests

            minLocalRequestFreeThreads="[count]" - minimum number of free thread to allow execution of new local requests

            appRequestQueueLimit="[count]" - maximum number of requests queued for the application

           

            If you change the maxRequestLength setting, you should also change the Media.MaxSizeInDatabase setting.

            Media.MaxSizeInDatabase should always be less than maxRequestLength.

          -->

          <httpRuntime maxRequestLength="16384" executionTimeout="600" />