IS 7 預設檔案上傳大小時30M
要突破這個限制:
1. 修改IIS的applicationhost.config
開啟 %windir%\system32\inetsrv\config\applicationhost.config
找到: <requestFiltering>節點,
這個節點預設沒有 <requestLimits maxAllowedContentLength="上傳大小的值(單位:byte)" /> 元素,IIS 7和IIS 7.5上測試過 最大值只能是<requestLimits maxAllowedContentLength="4294967295" /> <4GB,
為這個節點新增如下案例元素:<requestLimits maxAllowedContentLength="2147483647" /> ,上傳的大小將改為2G
注意: %windir%\system32\inetsrv\config\applicationhost.config 檔案一定不要用其他機器的檔案替換,否則IIS將無法啟動
此檔案記錄了,當前IIS中所有Site , App pool的資訊,還有一些與機器相關的配置。
2 修改web.config
<system.web>
<httpRuntime executionTimeout="36000" maxRequestLength="2097151"/> <!--maxRequestLength:上傳的大小,單位K ,executionTimeout:設定逾時時間,單位:秒。(預設是90秒) -->
</system.web>
注意:這個maxRequestLength最大值只能是2097151K,設定大於這個值將會出現如下錯誤:
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: The value for the property 'maxRequestLength' is not valid. The error is: The value must be inside the range 0-2097151.
Source Error:
Line 117: <httpHandlers />
Line 118: <customErrors mode="RemoteOnly" />
Line 119: <httpRuntime executionTimeout="36000" maxRequestLength="4194304" />
Line 120: <authentication mode="Windows" />
Line 121: <identity impersonate="true" />
3. web.config下如果有如下節點(此節點是為IIS 7設計的) ,則修改
<requestLimits maxAllowedContentLength="2147483647" /> 單位與applicationhost.config中的<requestLimits maxAllowedContentLength="2147483647" />一致,它的最大值也只能為4294967295
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>
總結:asp.net(IIS 7 and IIS 7.5)上傳檔案的最大值不能超過2GB