Maximum request length exceeded.

2018-12-31 02:08发布

I am getting the error Maximum request length exceeded when I am trying to upload a video in my site.

How do I fix this?

14条回答
看风景的人
2楼-- · 2018-12-31 02:14

To summarize all the answers in a single place:

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

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

Rules:

  • maxRequestLength (expressed in kb) value must match maxAllowedContentLength (expressed in bytes).
  • most of the time your system.web section may already contains an "httpRuntime". set your targetFramework to the version of your .net used.

Notes:

  • default value for maxRequestLength is 4096 (4mb). max value is 2,147,483,647
  • default value for maxAllowedContentLength is 30,000,000 (around 30mb). max value is 4,294,967,295

more info MSDN

查看更多
泪湿衣
3楼-- · 2018-12-31 02:15

I had to edit the C:\Windows\System32\inetsrv\config\applicationHost.config file and add <requestLimits maxAllowedContentLength="1073741824" /> to the end of the...

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

section.

As per This Microsoft Support Article

查看更多
步步皆殇っ
4楼-- · 2018-12-31 02:15

I can add to config web uncompiled

<system.web> 
  <httpRuntime maxRequestLength="1024" executionTimeout="3600" /> 
  <compilation debug="true"/> 
</system.web> 
<security> 
  <requestFiltering> 
    <requestLimits maxAllowedContentLength="1048576"/> 
  </requestFiltering> 
</security>
查看更多
大哥的爱人
5楼-- · 2018-12-31 02:17

The maximum request size is, by default, 4mb (4096 KB)

This is explained here: http://support.microsoft.com/default.aspx?scid=kb;EN-US;295626

The above article also explains how to fix this issue :)

查看更多
牵手、夕阳
6楼-- · 2018-12-31 02:18

And just in case someone's looking for a way to handle this exception and show a meaningful explanation to the user (something like "You're uploading a file that is too big"):

//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 or later required)

查看更多
何处买醉
7楼-- · 2018-12-31 02:18

If you can't update configuration files but control in full the code that handles uploaded files use HttpContext.Current.Request.GetBufferlessInputStream(true).

The true value for disableMaxRequestLength parameter tells the framework to ignore configured request limits.

For detailed description visit https://msdn.microsoft.com/en-us/library/hh195568(v=vs.110).aspx

查看更多
登录 后发表回答