嘗試在網站上上傳視頻時,出現錯誤「 最大請求長度超出」 。 web
我該如何解決? app
我認爲這裏沒有提到它,可是要使其正常工做,我必須在web.config中提供如下兩個值: 網站
在system.web
spa
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
並在system.webServer
code
<security> <requestFiltering> <requestLimits maxAllowedContentLength="1073741824" /> </requestFiltering> </security>
重要說明 :這兩個值必須匹配。 在這種狀況下,個人最大上傳大小爲1024 MB。 視頻
maxRequestLength有1048576 KILOBYTES ,maxAllowedContentLength有1073741824 BYTES 。 it
我知道這很明顯,可是很容易忽略。 io
可能值得注意的是,您可能但願將此更改限制爲但願用於上傳的URL,而不是整個站點。 ast
<location path="Documents/Upload"> <system.web> <!-- 50MB in kilobytes, default is 4096 or 4MB--> <httpRuntime maxRequestLength="51200" /> </system.web> <system.webServer> <security> <requestFiltering> <!-- 50MB in bytes, default is 30000000 or approx. 28.6102 Mb--> <requestLimits maxAllowedContentLength="52428800" /> </requestFiltering> </security> </system.webServer> </location>
而且以防萬一有人在尋找一種方法來處理此異常並向用戶顯示有意義的解釋(例如「您正在上傳的文件太大」): object
//Global.asax private void Application_Error(object sender, EventArgs e) { var ex = Server.GetLastError(); var httpException = ex as HttpException ?? ex.InnerException as HttpException; if(httpException == null) return; if(httpException.WebEventCode == WebEventCodes.RuntimeErrorPostTooLarge) { //handle the error Response.Write("Too big a file, dude"); //for example } }
(須要ASP.NET 4或更高版本)
若是您有請求前往站點中的應用程序,請確保在根web.config中設置maxRequestLength。 應用程序的web.config中的maxRequestLength彷佛被忽略了。
maxRequestLength(以KB爲單位的長度)如前所述。 我花了1024(1MB)maxAllowedContentLength(長度以字節爲單位)應該與您的maxRequestLength(1048576字節= 1MB)相同。
<system.web> <httpRuntime maxRequestLength="1024" executionTimeout="3600" /> </system.web> <system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="1048576"/> </requestFiltering> </security> </system.webServer>