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

后端 未结 15 2927
青春惊慌失措
青春惊慌失措 2020-11-22 06:09

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

相关标签:
15条回答
  • 2020-11-22 06:10

    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.

    0 讨论(0)
  • 2020-11-22 06:11

    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

    0 讨论(0)
  • 2020-11-22 06:12

    If you are using Framework 4.6

    <httpRuntime targetFramework="4.6.1" requestValidationMode="2.0" maxRequestLength="10485760"  />
    
    0 讨论(0)
  • 2020-11-22 06:13

    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

    0 讨论(0)
  • 2020-11-22 06:14

    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.

    0 讨论(0)
  • 2020-11-22 06:16

    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.

    0 讨论(0)
提交回复
热议问题