How to increase the max upload file size in ASP.NET? How to increase the max upload file size in ASP.NET? asp.net asp.net

How to increase the max upload file size in ASP.NET?


This setting goes in your web.config file. It affects the entire application, though... I don't think you can set it per page.

<configuration>  <system.web>    <httpRuntime maxRequestLength="xxx" />  </system.web></configuration>

"xxx" is in KB. The default is 4096 (= 4 MB).


For IIS 7+, as well as adding the httpRuntime maxRequestLength setting you also need to add:

  <system.webServer>    <security>      <requestFiltering>        <requestLimits maxAllowedContentLength="52428800" /> <!--50MB-->      </requestFiltering>    </security>  </system.webServer>

Or in IIS (7):

  • Select the website you want enable to accept large file uploads.
  • In the main window double click 'Request filtering'
  • Select "Edit Feature Settings"
  • Modify the "Maximum allowed content length (bytes)"


To increase uploading file's size limit we have two ways

1.IIS6 or lower

By default, in ASP.Net the maximum size of a file to be uploaded to the server is around 4MB. This value can be increased by modifying the maxRequestLength attribute in web.config.

Remember : maxRequestLenght is in KB

Example: if you want to restrict uploads to 15MB, set maxRequestLength to “15360” (15 x 1024).

<system.web>   <!-- maxRequestLength for asp.net, in KB -->    <httpRuntime maxRequestLength="15360" ></httpRuntime> </system.web>

2.IIS7 or higher

A slight different way used here to upload files.IIS7 has introduced request filtering module.Which executed before ASP.Net.Means the way pipeline works is that the IIS value(maxAllowedContentLength) checked first then ASP.NET value(maxRequestLength) is checked.The maxAllowedContentLength attribute defaults to 28.61 MB.This value can be increased by modifying both attribute in same web.config.

Remember : maxAllowedContentLength is in bytes

Example : if you want to restrict uploads to 15MB, set maxRequestLength to “15360” and maxAllowedContentLength to "15728640" (15 x 1024 x 1024).

<system.web>   <!-- maxRequestLength for asp.net, in KB -->    <httpRuntime maxRequestLength="15360" ></httpRuntime> </system.web><system.webServer>                 <security>       <requestFiltering>          <!-- maxAllowedContentLength, for IIS, in bytes -->          <requestLimits maxAllowedContentLength="15728640" ></requestLimits>      </requestFiltering>    </security></system.webServer>

MSDN Reference link : https://msdn.microsoft.com/en-us/library/e1f13641(VS.80).aspx