Se superó la longitud máxima de la solicitud.

Resuelto Surya sasidhar asked hace 13 años • 16 respuestas

Recibo el error Se excedió la longitud máxima de la solicitud cuando intento cargar un video en mi sitio.

¿Cómo puedo solucionar esto?

Surya sasidhar avatar Oct 04 '10 15:10 Surya sasidhar
Aceptado

Si está utilizando IIS para alojar su aplicación, el tamaño predeterminado del archivo de carga es 4 MB. Para aumentarlo, utilice la siguiente sección en su web.config:

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

Para IIS7 y superior, también debe agregar las líneas siguientes:

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

Nota :

  • maxRequestLengthse mide en kilobytes
  • maxAllowedContentLengthse mide en bytes

es por eso que los valores difieren en este ejemplo de configuración. (Ambos equivalen a 1 GB).

Sachin Shanbhag avatar Oct 04 '2010 08:10 Sachin Shanbhag

No creo que se haya mencionado aquí, pero para que esto funcione, tuve que proporcionar ambos valores en web.config:

Ensystem.web

<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />

Y ensystem.webServer

<security>
    <requestFiltering>
        <requestLimits maxAllowedContentLength="1073741824" />
    </requestFiltering>
</security>

IMPORTANTE : Ambos valores deben coincidir. En este caso, mi carga máxima es de 1024 megabytes.

maxRequestLength tiene 1048576 KILOBYTES y maxAllowedContentLength tiene 1073741824 BYTES .

Sé que es obvio, pero es fácil pasarlo por alto.

Karl avatar Sep 19 '2012 13:09 Karl

Puede que valga la pena señalar que es posible que desee limitar este cambio a la URL que espera que se utilice para la carga en lugar de a todo el sitio.

<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>
Nick Albrecht avatar May 06 '2013 16:05 Nick Albrecht

Y en caso de que alguien esté buscando una manera de manejar esta excepción y mostrar una explicación significativa al usuario (algo como "Estás subiendo un archivo que es demasiado grande"):

//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
    }
}

(Se requiere ASP.NET 4 o posterior)

Serge Shultz avatar May 23 '2015 19:05 Serge Shultz

El tamaño máximo de solicitud es, por defecto,4MB (4096 KB)

Esto se explica aquí .

El artículo anterior también explica cómo solucionar este problema :)

Dave avatar Oct 04 '2010 08:10 Dave