2021年2月2日 星期二

[ASP.Net] Maximum request length exceeded. 超過上傳檔案限制

如何解決在上傳檔案時遇到檔案過大的錯誤排解

ASP.NET讀取資料或上傳檔案時的預設檔案大小是4MB,因此會直接出現下面的情形

錯誤訊息如下:

Maximum request length exceeded.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Maximum request length exceeded.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.



解決方法:

在Web.Config中加上以下資訊

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

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