Maximum request length exceeded.

前端 未结 14 2734
臣服心动
臣服心动 2020-11-21 07:37

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条回答
  • 2020-11-21 08:01

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

    (ASP.NET 4 or later required)

    0 讨论(0)
  • 2020-11-21 08:01

    If you can't update configuration files but control the code that handles file uploads 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

    0 讨论(0)
  • 2020-11-21 08:02

    If you are using IIS for hosting your application, then the default upload file size is 4MB. To increase it, please use this below section in your web.config -

    <configuration>
        <system.web>
            <httpRuntime maxRequestLength="1048576" />
        </system.web>
    </configuration>
    

    For IIS7 and above, you also need to add the lines below:

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

    Note:

    • maxRequestLength is measured in kilobytes
    • maxAllowedContentLength is measured in bytes

    which is why the values differ in this config example. (Both are equivalent to 1 GB.)

    0 讨论(0)
  • 2020-11-21 08:03

    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

    0 讨论(0)
  • 2020-11-21 08:08

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

    This is explained here.

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

    0 讨论(0)
  • 2020-11-21 08:09

    I was tripped up by the fact that our web.config file has multiple system.web sections: it worked when I added < httpRuntime maxRequestLength="1048576" /> to the system.web section that at the configuration level.

    0 讨论(0)
提交回复
热议问题