Asp.net

IIS7 - 請求過濾模組配置為拒絕超過請求內容長度的請求

  • June 3, 2012

我想上傳圖片,它在我的機器上執行良好,但是當我將我的網站放在 IIS7 伺服器上公開時,我無法上傳任何東西。

錯誤

請求過濾模組,用於拒絕超過請求內容長度的請求。

最可能的原因

Web 伺服器上配置了請求過濾,以拒絕請求,因為內容長度超過了配置的值。

你可以嘗試的事情

驗證 applicationhost.config 或 web.config 文件中的 configuration/system.webServer/security/requestFiltering/requestLimits@maxAllowedContentLength 設置。

Web.config 中的 system.webServer

 <system.webServer>
   <validation validateIntegratedModeConfiguration="false" />
   <modules runAllManagedModulesForAllRequests="true" />
   <security>
     <requestFiltering>
        <requestLimits maxAllowedContentLength="1048576" />
     </requestFiltering>
  </security>
 </system.webServer>

如您所見,我將 maxAllowedContentLength 設置為 1gb。重新啟動我的網站,仍然收到此錯誤。我/uploads/在我的文件系統上創建了一個文件夾,它應該也是。不知道是什麼導致了這個錯誤以及為什麼我不能上傳圖片。

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

這裡

對於 IIS7 及更高版本,您還需要添加以下行:

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

引用自:https://stackoverflow.com/questions/10871881