当我试图在我的网站上上传视频时,我得到错误的最大请求长度超过了。

我怎么解决这个问题?


当前回答

我被我们的网绊倒了。配置文件有多个系统。web部分:当我添加< httpRuntime maxRequestLength="1048576" />到系统时,它工作了。Web部分的配置级别。

其他回答

如果你不能更新配置文件,但是控制了处理文件上传的代码,请使用HttpContext.Current.Request.GetBufferlessInputStream(true)。

disableMaxRequestLength参数的true值告诉框架忽略配置的请求限制。

详情请访问https://msdn.microsoft.com/en-us/library/hh195568(v=vs.110).aspx

我必须编辑C:\Windows\System32\inetsrv\config\applicationHost。将<requestLimits maxAllowedContentLength="1073741824" />添加到…

<configuration>
    <system.webServer>
        <security>
            <requestFiltering>

部分。

根据这篇微软支持文章

如果有人正在寻找一种方法来处理这个异常,并向用户显示一个有意义的解释(比如“你正在上传一个太大的文件”):

//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 (((System.Web.HttpException)httpException.InnerException).WebEventCode == System.Web.Management.WebEventCodes.RuntimeErrorPostTooLarge)
    {
        //handle the error
        Response.Write("Too big a file, dude"); //for example
    }
}

(ASP。需要net4或以上版本)

我正在处理同样的错误,花时间解决后,添加以下行在web。配置文件

<system.web>
   <httpRuntime targetFramework="4.7.1" maxRequestLength="1048576"/>
</system.web>

and

 <system.webServer>
   <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
    </security>
</system.webServer>

默认情况下,最大请求大小为4MB (4096 KB)

这里解释一下。

上面的文章也解释了如何解决这个问题:)