IIS7默認文件上傳大小是30M,那么超過30M的文件就無法上傳了,那么就需要對IIS的配置文件進行修改。
在實際應用中往往會出現上傳文件太大,無法上傳的情況,那是因為IIS對上傳文件大小有限制,IIS7默認文件上傳大小是30M,要突破這個限制需要做一下修改:
1、打開%windir%/system32/inetsrv/config/applicationhost.config找到:<requestFiltering>節點
這個節點默認沒有<requestLimitsmaxAllowedContentLength="上傳大小的值(單位:byte)"/>元素,IIS7和IIS7.5上測試過最大值只能是<requestLimitsmaxAllowedContentLength="4294967295"/><4GB,
為這個節點新增如下事例元素:<requestLimitsmaxAllowedContentLength="2147483647"/>,上傳的大小將改為2G
注意:%windir%/system32/inetsrv/config/applicationhost.config文件一定不要用其他機器的文件替換,否則IIS將無法啟動此文件記錄了,當前IIS中所有Site,Apppool的信息,還有一些與機器相關的配置。
2、修改web.config
<system.web>
<httpRuntimeexecutionTimeout="36000"maxRequestLength="2097151"/>
<!--maxRequestLength:上傳的大小,單位K,executionTimeout:設置超時時間,單位:秒。(默認是90秒)-->
</system.web>
3、web.config下如果有如下節點(此節點是為IIS7設計的),則修改:
<requestLimitsmaxAllowedContentLength="2147483647"/>單位與applicationhost.config中的<requestLimitsmaxAllowedContentLength="2147483647"/>一致,它的最大值也只能為4294967295<system.webServer>
<security>
<requestFiltering>
<requestLimitsmaxAllowedContentLength="2147483647"/>
</requestFiltering>
</security>
</system.webServer>