引言
之前使用Uploadify做了一個上傳圖片並預覽的功能,今天在項目中,要使用該插件上傳大文件。之前弄過上傳圖片的demo,就使用該demo進行測試。可以查看我的這篇文章:[Asp.net]Uploadify所有配置說明,常見bug問題分析。
大文件上傳
第一步:修改uploadify參數
1 'fileSizeLimit': '0',//單個文件大小,0為無限制,可接受KB,MB,GB等單位的字符串值 2 'fileTypeDesc': '文件',//文件描述Image Files 3 'fileTypeExts': '*.zip; *.rar; *.png',//允許上傳的文件類型
測試,用一個大於30M的文件,進行上傳測試。
第二步:修改web.config
1 <configuration> 2 <system.web> 3 <compilation debug="true" targetFramework="4.5" /> 4 <!--maxRequestLength就是文件的最大字符數,最大值不能超過2個G左右,executionTimeout是超時時間--> 5 <httpRuntime targetFramework="4.5" maxRequestLength="1073741824" executionTimeout="3600" /> 6 </system.web> 7 </configuration>
測試,仍使用上面的文件,進行上傳測試。
第三步:添加system.webServer節點
1 <configuration> 2 <system.web> 3 <compilation debug="true" targetFramework="4.5" /> 4 <!--maxRequestLength就是文件的最大字符數,最大值不能超過2個G左右,executionTimeout是超時時間--> 5 <httpRuntime targetFramework="4.5" maxRequestLength="1073741824" executionTimeout="3600" /> 6 </system.web> 7 <system.webServer> 8 <security> 9 <requestFiltering> 10 <!--修改服務器允許最大長度--> 11 <requestLimits maxAllowedContentLength="1073741824"/> 12 </requestFiltering> 13 </security> 14 </system.webServer> 15 </configuration>
測試,仍然用上面的文件,進行上傳測試:
設置IIS
打開IIS管理器,找到Default Web Site。先進行停止。
在IIS中雙擊“請求篩選”打開。
點擊右邊的“編輯功能設置”,打開“編輯請求篩選設置”對話框。
其中的允許的最大容量長度,默認是”30000000“,30M,將其修改為1073741824,即1G。
啟動IIS.
總結
在項目中遇到了這樣的問題,也花了點時間找解決方案,覺得既然花費了時間去找解決方案,就有必要總結一下,希望能幫到遇到同樣問題的你。 這里不再提供demo,以可以從我上篇文章中下載,注意修改的地方已在本文章說明。