設置文件上傳的最大大小


系統環境:win8

開發環境:asp.net mvc

功能:文件上傳

在上傳文件時,比較小的文件會直接上傳成功,大的文件頁面報錯:“文件超過了最大請求長度”。

經過查明:

需要在配置文件里面設置文件上傳限定的兩個屬性值:maxAllowedContentLength,maxRequestLength 允許上傳文件的長度,和請求的長度,兩個大小需要設置一致,如果不一致,則以請求長度為准。

The maximum request size in kilobytes. The default size is 4096 KB (4 MB). 默認請求長度只有4M.   設置的單位都為byte

<system.web>
  <httpRuntime maxRequestLength="2147483647" executionTimeout="36000" delayNotificationTimeout="36000"/>
</system.web>

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

以上是對某個站點或者某個應用上限制大小,配置的web.config

要以上配置有效的前提是,要確保applicationhost.config中對該項修改的權限已經放開。

applicationhost.config文件路徑在 C:\Windows\System32\inetsrv\config 下

可通過如下設置進行更改:

modify the overrideModeDefault from "Deny" to "Allow" like so: 

<sectionGroup name="system.webServer">

  <sectionGroup name="security">
       <section name="requestFiltering" overrideModeDefault="Allow" />

  </sectionGroup>
</sectionGroup>

確認修改過applicationhost.config中上述設置以后,再進行web.config中的設置。

 

二: 也可以直接設置服務器級別的文件上傳大小,在applicationhost.config文件中加上以下字段

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

也可以使用命令模式修改:

也可以使用命令行模式修改applicationhost.config:

%windir%\system32\inetsrv\appcmd set config -section:requestFiltering -requestLimits.maxAllowedContentLength:2147483647

命令模式尚未試過。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM