超过了最大请求长度。

尝试在网站上上传视频时,出现错误“ 最大请求长度超出”web

我该如何解决? app


#1楼

我认为这里没有提到它,可是要使其正常工做,我必须在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 BYTESit

我知道这很明显,可是很容易忽略。 io


#2楼

可能值得注意的是,您可能但愿将此更改限制为但愿用于上传的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>

#3楼

而且以防万一有人在寻找一种方法来处理此异常并向用户显示有意义的解释(例如“您正在上传的文件太大”): 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或更高版本)


#4楼

若是您有请求前往站点中的应用程序,请确保在根web.config中设置maxRequestLength。 应用程序的web.config中的maxRequestLength彷佛被忽略了。


#5楼

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>
相关文章
相关标签/搜索