IIS7 預設檔案上傳大小是30M,那麼超過30M的檔案就無法上傳了,那麼就需要對IIS的設定檔進行修改。
在實際應用中往往會出現上傳檔案太大,無法上傳的情況,那是因為IIS對上傳檔案大小有限制,IIS7 預設檔案上傳大小是30M,要突破這個限制需要做一下修改:
1.開啟 %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>
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>