前端Input file上傳文件超長 超過大小限制


 

系統環境:win7 IIS7.5

開發環境:asp.net WF

功能:文件上傳

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

 

 

經過查看在web.conf配置里面有

  <system.web>

    <httpRuntime maxRequestLength="102400" executionTimeout="60" appRequestQueueLimit="100" />

  </system.web>

設置為了的是100M的文件大小,可是依舊是無法上傳成功,后來發現需要對IIS進行設置

 

1. 修改IIS的applicationhost.config

 

文件位置: %windir%/system32/inetsrv/config/applicationhost.config

  找到<requestFiltering>節點,該節點下默認沒有 <requestLimits maxAllowedContentLength="上傳大小的值(單位:byte)" /> 元素。為這個節點添加如下元素:<requestLimits maxAllowedContentLength="2147483647" />  (上傳的大小將改為2G)

 

需要在配置文件里面設置文件上傳限定的兩個屬性值: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>


免責聲明!

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



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