.NET component, ASP.NET controls .NET component, ASP.NET controls
Skip Navigation LinksHome > Support > Knowledge Base > Maximum request length exceeded

Question: Why do I get an error System.Web.HttpException: Maximum request length exceeded.

Summary:

Many developers face with this exception when they integrate file upload functionality to the asp.net web application. This exception is thrown because incoming request is greater than allowed maximum request length. By default ASP.NET http runtime allows to receive requests that are not greater than 4 MB. This value can be increased by specifying maxRequestLength parameter of <httpRuntime> section of the configuration file (see section "SOLUTION").

In truth, you will see mentioned error message when you are running you project on the local machine(http://localhost) only. On the remote host you will get "The page cannot be displayed" message or an empty/white page. It happens because the browser can't get any response from the server while the whole request will not be sent. So there is no way to handle "Maximum request length exceeded" exception and displaying user friendly message without reading the whole request.

The EAUpload component has a two options for solving mentioned issue.
They are:

  • Read the whole request and then throw an exeption that can be handle on the application level(Global class).
  • Begin read request, check the file size through ajax request and, if file size exceed allowed limit, terminate an upload.
    You can see examples which realize this technique by following links:
    File Upload with Ajax progress bar
    Ajax file upload


Solution:

The EAUpload component can processing uploads of up to 4 gigabytes. However, when using the product in .NET, it is important to configure the application settings to make sure ASP.NET doesn't block the large uploads before EAUpload can process them.
To work around this problem, increase the value of allowed request length.

You can do that by following two ways:

Method 1:
EAUpload component provides a replacement of MaxRequestLength attribute of httpRuntime config section. If MaxRequestLength parameter of EAUpload environment is defined then request have allowed length that is specified by this parameter and maxRequestLength parameter of httpRuntime configuration section is ignored. The specified value will take effect only for requests which are processed by EAUpload component. The value that is specified in maxRequestLength attribute will be actually for other requests.

Set the MaxRequestLength parameter value in the EAUpload configuration

  • Open the Web.config file in Notepad.
  • Increase the value of the MaxRequestLength parameter to avoid errors.
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    ...
       <EasyAlgo.EAUpload>
           <Environment
               ...                
    
               ExacutionTimeout="3600"
               // Set maximum content length to 1GB.
               MaxRequestLength="1048576"        
    
               ...
           />
           <ErrorsProcessing
                ...                   
            />
        </EasyAlgo.EAUpload>
    ... 
    </configuration>    
    
  • Save the Web.config file.

Method 2:
The maxRequestLength attribute exists under httpRequest in the Machine.config file. You can change these settings either in the Web.Config file or in the Machine.config file. The default value for the maximum request length is 4096 KB (4MB). The maxRequestLength attribute indicates the maximum file upload size supported by ASP.NET. This limit can be used to prevent denial of service attacks caused by users posting large files to the server. The size specified is in kilobytes.

Figure A: Set the maxRequestLength attribute value in the Web.config File

  • Open the Web.config file in Notepad.
  • Add the httpRuntime element in the system.web section as follows:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    ...
     <system.web>
       <httpRuntime 
             executionTimeout="90"
             maxRequestLength="4096"/>
     </system.web>
    ... 
    </configuration>
    
  • Increase the value of the maxRequestLength attribute to avoid errors.
  • Save the Web.config file.

Figure B: Set the maxRequestLength attribute value in the Machine.config File

  • Open the Machine.config file in Notepad. The Machine.config file is located in the %SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\ directory.
  • In the Machine.config file, locate the httpRuntime element.
    <httpRuntime 
        executionTimeout="90"
        maxRequestLength="4096"
    	useFullyQualifiedRedirectUrl="false"
    	minFreeThreads="8"
    	minLocalRequestFreeThreads="4"
    	appRequestQueueLimit="100" />
    
  • Increase the value of the maxRequestLength attribute to avoid errors.
  • Save the Web.config file.


References:

Configures ASP.NET HTTP runtime settings:
http://msdn2.microsoft.com/en-us/library/e1f13641(vs.71).aspx

Cannot Upload Large Files When You Use the HtmlInputFile Server Control:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;295626



Site Map Asp.net upload component, flash file uploader  Privacy Asp.net upload component, flash file uploader  Terms of Use
Asp.net upload component, flash file uploader ©2014 EasyAlgo Software. All Rights Reserved.
EasyAlgo Software