[c#] How to increase the max upload file size in ASP.NET?

I have a form that excepts a file upload in ASP.NET. I need to increase the max upload size to above the 4 MB default.

I have found in certain places referencing the below code at msdn.

[ConfigurationPropertyAttribute("maxRequestLength", DefaultValue = )]

None of the references actually describe how to use it, and I have tried several things with no success. I only want to modify this attribute for certain pages that are asking for file upload.

Is this the correct route to take? And how do I use this?

This question is related to c# .net asp.net file-upload

The answer is


I've the same problem in a win 2008 IIS server, I've solved the problem adding this configuration in the web.config:

<system.web>
    <httpRuntime executionTimeout="3600" maxRequestLength="102400" 
     appRequestQueueLimit="100" requestValidationMode="2.0"
     requestLengthDiskThreshold="10024000"/>
</system.web>

The requestLengthDiskThreshold by default is 80000 bytes so it's too small for my application. requestLengthDiskThreshold is measured in bytes and maxRequestLength is expressed in Kbytes.

The problem is present if the application is using a System.Web.UI.HtmlControls.HtmlInputFile server component. Increasing the requestLengthDiskThreshold is necessary to solve it.


If it works in your local machine and does not work after deployment in IIS (i used Windows Server 2008 R2) i have a solution.

Open IIS (inetmgr) Go to your website At right hand side go to Content (Request Filtering) Go to Edit Feature Settings Change maximum content size as (Bytes you required) This will work. You can also take help from following thread http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits


I believe this line in the web.config will set the max upload size:

<system.web>

        <httpRuntime maxRequestLength="600000"/>
</system.web>

If you use sharepoint you should configure max size with Administrative Tools too: kb925083


I believe this line in the web.config will set the max upload size:

<system.web>

        <httpRuntime maxRequestLength="600000"/>
</system.web>

I know it is an old question.

So this is what you have to do:

In you web.config file, add this in <system.web>:

<!-- 3GB Files / in kilobyte (3072*1024) -->
<httpRuntime targetFramework="4.5" maxRequestLength="3145728"/>

and this under <system.webServer>:

<security>
    <requestFiltering>

      <!-- 3GB Files / in byte (3072*1024*1024) -->
      <requestLimits maxAllowedContentLength="3221225472" />

    </requestFiltering>
</security>

You see in the comment how this works. In one you need to have the sie in bytes and in the other one in kilobytes. Hope that helps.


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

I know it is an old question.

So this is what you have to do:

In you web.config file, add this in <system.web>:

<!-- 3GB Files / in kilobyte (3072*1024) -->
<httpRuntime targetFramework="4.5" maxRequestLength="3145728"/>

and this under <system.webServer>:

<security>
    <requestFiltering>

      <!-- 3GB Files / in byte (3072*1024*1024) -->
      <requestLimits maxAllowedContentLength="3221225472" />

    </requestFiltering>
</security>

You see in the comment how this works. In one you need to have the sie in bytes and in the other one in kilobytes. Hope that helps.


Max file size can be restricted to a single MVC Controller or even to an Action.
web.config <location> tag can be used for this:

<location path="YourAreaName/YourControllerName>/YourActionName>">
  <system.web>
    <!-- 15MB maxRequestLength for asp.net, in KB 15360 -->
    <httpRuntime maxRequestLength="15360" />
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
        <!-- 15MB maxAllowedContentLength, for IIS, in bytes 15728640 -->
        <requestLimits maxAllowedContentLength="15728640" />
      </requestFiltering>
    </security>
  </system.webServer>
</location>

Or you can add these entries in area's own web.config.


for a 2 GB max limit, on your application web.config:

<system.web>
  <compilation debug="true" targetFramework="4.5" />
  <httpRuntime targetFramework="4.5" maxRequestLength="2147483647" executionTimeout="1600" requestLengthDiskThreshold="2147483647" />
</system.web>

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="2147483647" />
    </requestFiltering>
  </security>
</system.webServer>

If it works in your local machine and does not work after deployment in IIS (i used Windows Server 2008 R2) i have a solution.

Open IIS (inetmgr) Go to your website At right hand side go to Content (Request Filtering) Go to Edit Feature Settings Change maximum content size as (Bytes you required) This will work. You can also take help from following thread http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits


If you use ssl cert your ssl pipeline F5 settings configure.Important.


for a 2 GB max limit, on your application web.config:

<system.web>
  <compilation debug="true" targetFramework="4.5" />
  <httpRuntime targetFramework="4.5" maxRequestLength="2147483647" executionTimeout="1600" requestLengthDiskThreshold="2147483647" />
</system.web>

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="2147483647" />
    </requestFiltering>
  </security>
</system.webServer>

You can write that block of code in your application web.config file.

<httpRuntime maxRequestLength="2048576000" />
<sessionState timeout="3600"  />

By writing that code you can upload a larger file than now


If you use ssl cert your ssl pipeline F5 settings configure.Important.


If you are using Framework 4.6

<httpRuntime targetFramework="4.6.1" requestValidationMode="2.0" maxRequestLength="10485760"  />

If its windows 2003 / IIS 6.0 then check out AspMaxRequestEntityAllowed = "204800" in the file metabase.xml located in folder C:\windows\system32\inetsrv\

The default value of "204800" (~205Kb) is in my opinion too low for most users. Just change the value to what you think should be max.

If you cant save the file after editing it you have to either stop the ISS-server or enable the server to allow editing of the file:

alt text
(source: itmaskinen.se)

Edit: I did not read the question correct (how to set the maxrequest in webconfig). But this informatin may be of interrest for other people, many people who move their sites from win2000-server to win2003 and had a working upload-function and suddenly got the Request.BinaryRead Failed error will have use of it. So I leave the answer here.


I've the same problem in a win 2008 IIS server, I've solved the problem adding this configuration in the web.config:

<system.web>
    <httpRuntime executionTimeout="3600" maxRequestLength="102400" 
     appRequestQueueLimit="100" requestValidationMode="2.0"
     requestLengthDiskThreshold="10024000"/>
</system.web>

The requestLengthDiskThreshold by default is 80000 bytes so it's too small for my application. requestLengthDiskThreshold is measured in bytes and maxRequestLength is expressed in Kbytes.

The problem is present if the application is using a System.Web.UI.HtmlControls.HtmlInputFile server component. Increasing the requestLengthDiskThreshold is necessary to solve it.


If you are using Framework 4.6

<httpRuntime targetFramework="4.6.1" requestValidationMode="2.0" maxRequestLength="10485760"  />

If its windows 2003 / IIS 6.0 then check out AspMaxRequestEntityAllowed = "204800" in the file metabase.xml located in folder C:\windows\system32\inetsrv\

The default value of "204800" (~205Kb) is in my opinion too low for most users. Just change the value to what you think should be max.

If you cant save the file after editing it you have to either stop the ISS-server or enable the server to allow editing of the file:

alt text
(source: itmaskinen.se)

Edit: I did not read the question correct (how to set the maxrequest in webconfig). But this informatin may be of interrest for other people, many people who move their sites from win2000-server to win2003 and had a working upload-function and suddenly got the Request.BinaryRead Failed error will have use of it. So I leave the answer here.


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


I believe this line in the web.config will set the max upload size:

<system.web>

        <httpRuntime maxRequestLength="600000"/>
</system.web>

I have a blog post on how to increase the file size for asp upload control.

From the post:

By default, the FileUpload control allows a maximum of 4MB file to be uploaded and the execution timeout is 110 seconds. These properties can be changed from within the web.config file’s httpRuntime section. The maxRequestLength property determines the maximum file size that can be uploaded. The executionTimeout property determines the maximum time for execution.


If its windows 2003 / IIS 6.0 then check out AspMaxRequestEntityAllowed = "204800" in the file metabase.xml located in folder C:\windows\system32\inetsrv\

The default value of "204800" (~205Kb) is in my opinion too low for most users. Just change the value to what you think should be max.

If you cant save the file after editing it you have to either stop the ISS-server or enable the server to allow editing of the file:

alt text
(source: itmaskinen.se)

Edit: I did not read the question correct (how to set the maxrequest in webconfig). But this informatin may be of interrest for other people, many people who move their sites from win2000-server to win2003 and had a working upload-function and suddenly got the Request.BinaryRead Failed error will have use of it. So I leave the answer here.


I have a blog post on how to increase the file size for asp upload control.

From the post:

By default, the FileUpload control allows a maximum of 4MB file to be uploaded and the execution timeout is 110 seconds. These properties can be changed from within the web.config file’s httpRuntime section. The maxRequestLength property determines the maximum file size that can be uploaded. The executionTimeout property determines the maximum time for execution.


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


I believe this line in the web.config will set the max upload size:

<system.web>

        <httpRuntime maxRequestLength="600000"/>
</system.web>

If its windows 2003 / IIS 6.0 then check out AspMaxRequestEntityAllowed = "204800" in the file metabase.xml located in folder C:\windows\system32\inetsrv\

The default value of "204800" (~205Kb) is in my opinion too low for most users. Just change the value to what you think should be max.

If you cant save the file after editing it you have to either stop the ISS-server or enable the server to allow editing of the file:

alt text
(source: itmaskinen.se)

Edit: I did not read the question correct (how to set the maxrequest in webconfig). But this informatin may be of interrest for other people, many people who move their sites from win2000-server to win2003 and had a working upload-function and suddenly got the Request.BinaryRead Failed error will have use of it. So I leave the answer here.


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

Max file size can be restricted to a single MVC Controller or even to an Action.
web.config <location> tag can be used for this:

<location path="YourAreaName/YourControllerName>/YourActionName>">
  <system.web>
    <!-- 15MB maxRequestLength for asp.net, in KB 15360 -->
    <httpRuntime maxRequestLength="15360" />
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
        <!-- 15MB maxAllowedContentLength, for IIS, in bytes 15728640 -->
        <requestLimits maxAllowedContentLength="15728640" />
      </requestFiltering>
    </security>
  </system.webServer>
</location>

Or you can add these entries in area's own web.config.


If you use sharepoint you should configure max size with Administrative Tools too: kb925083


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to .net

You must add a reference to assembly 'netstandard, Version=2.0.0.0 How to use Bootstrap 4 in ASP.NET Core No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization .net Core 2.0 - Package was restored using .NetFramework 4.6.1 instead of target framework .netCore 2.0. The package may not be fully compatible Update .NET web service to use TLS 1.2 EF Core add-migration Build Failed What is the difference between .NET Core and .NET Standard Class Library project types? Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies Nuget connection attempt failed "Unable to load the service index for source" Token based authentication in Web API without any user interface

Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to file-upload

bootstrap 4 file input doesn't show the file name How to post a file from a form with Axios File Upload In Angular? How to set the max size of upload file The request was rejected because no multipart boundary was found in springboot Send multipart/form-data files with angular using $http File upload from <input type="file"> How to upload files in asp.net core? REST API - file (ie images) processing - best practices Angular - POST uploaded file