IIS 檔案上傳的大小限制 File Upload Limit (MaxRequestLength, MaxAllowedContentLength)


  1. 說明
    1. IIS 部分
    2. ASP.NET 部分
    3. UploadAheadSize
  2. 參考資料

筆記 IIS 檔案上傳發生因檔案大小限制 (413.1 Content Length Too Large),實體不足無法正確上傳檔案時的處理方式。

logo

說明

檔案上傳大小的限制分別受到 IIS 與 ASP 的限制,要分別進行調整。

常用大小組合:

IIS maxAllowedContentLength ASP.NET maxRequestLength
10MB 10485760 102400
30MB 31457280 307200
50MB 52484800 512000
100MB 104857600 1024000
200MB 209715200 2048000
500MB 524288000 5120000
1GB 1048576000 10240000

IIS 部分

藉由調整 maxAllowedContentLength來設定 IIS 所允許的檔案上傳大小,預設值為 30000000 相當於 28.6 MB,調整為 104857600 相當於 100 MB。

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

另外也可以使用 GUI 來在要求篩選 (Filter Request) 設定:

ASP.NET 部分

An optional read/write sint32 value that specifies the limit, in kilobytes, for the input stream buffering threshold. The default is 4096 (4 MB). You can use this limit to prevent denial of service attacks that are caused, for example, by users posting large files to the server.
learn.microsoft.com

藉由設定 maxRequestLength來調整 ASP.NET 所允許的檔案上傳大小,預設值為 4096 KB,調整為 1024000 KB 相當於 100 MB。

 <system.web> 
    <httpRuntime 
        maxRequestLength="102400" 
        executionTimeout="3600" 
        appRequestQueueLimit="10000" 
        requestValidationMode="2.0" 
        enableVersionHeader="false"/>
</system.web> 

UploadAheadSize

一般情況下不需要特別進行此調整,但如果上述調整如何仍無法正常,可以嘗試調整。

設定的層級是伺服器或者是網站,無法針對個別應用系統或虛擬目錄去設定。

參考資料

File Upload 上傳檔案大小的限制

Which gets priority, maxRequestLength or maxAllowedContentLength

Request Limits

HttpRuntimeSection Class