Cómo aumentar el tamaño máximo de archivo de carga en ASP.NET?


Tengo un formulario que exceptúa la carga de un archivo en ASP.NET. Necesito aumentar el tamaño máximo de carga por encima del valor predeterminado de 4 MB.

He encontrado en ciertos lugares haciendo referencia al siguiente código en msdn.

[ConfigurationPropertyAttribute("maxRequestLength", DefaultValue = )]

Ninguna de las referencias en realidad describen cómo usarlo, y he intentado varias cosas sin éxito. Solo quiero modificar este atributo para ciertas páginas que están pidiendo la carga de archivos.

¿Es esta la ruta correcta a seguir? Y cómo uso ¿esto?

Author: John Saunders, 2008-11-14

14 answers

Esta configuración va en su web.archivo de configuración. Sin embargo, afecta a toda la aplicación... No creo que puedas configurarlo por página.

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

"xxx" está en KB. El valor predeterminado es 4096 (=4 MB).

 346
Author: Eric Rosenberger,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-18 15:38:21

Para IIS 7+, además de agregar la configuración httpRuntime maxRequestLength, también debe agregar:

  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="52428800" /> <!--50MB-->
      </requestFiltering>
    </security>
  </system.webServer>

O en IIS (7):

  • Seleccione el sitio web que desea habilitar para aceptar cargas de archivos grandes.
  • En la ventana principal, haga doble clic en 'Solicitar filtrado'
  • Seleccione "Editar Configuración de características"
  • Modificar la "Longitud máxima permitida de contenido (bytes)"
 147
Author: 4imble,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-11-13 17:20:08

Para aumentar el límite de tamaño del archivo de carga tenemos dos maneras

1. IIS6 o inferior

Por defecto, en ASP.Net el tamaño máximo de un archivo que se cargará en el servidor es alrededor de 4MB. Este valor se puede aumentar modificando el Atributo maxRequestLength en web.config .

Recuerde: maxRequestLenght está en KB

Ejemplo: si desea restringir las cargas a 15MB, establezca maxRequestLength to "15360" (15 x 1024).

<system.web>
   <!-- maxRequestLength for asp.net, in KB --> 
   <httpRuntime maxRequestLength="15360" ></httpRuntime> 
</system.web>

2. IIS7 o superior

Una forma ligeramente diferente utilizada aquí para cargar archivos.IIS7 has introducido módulo de filtrado de solicitudes .Que ejecutó antes ASP. Net. Significa que la forma en que funciona la tubería es que el IIS value ( maxAllowedContentLength ) comprobado primero entonces ASP.NET se comprueba el valor(maxRequestLength).La longitud del contenido máximo permitido el atributo por defecto es 28.61 MB.Este valor se puede aumentar por modificando ambos atributos en la misma web.config .

Recuerde: maxAllowedContentLength está en bytes

Ejemplo : si desea restringir las cargas a 15MB, establezca maxRequestLength en "15360" y maxAllowedContentLength en "15728640" (15 x 1024 x 1024).

<system.web>
   <!-- maxRequestLength for asp.net, in KB --> 
   <httpRuntime maxRequestLength="15360" ></httpRuntime> 
</system.web>

<system.webServer>              
   <security> 
      <requestFiltering> 
         <!-- maxAllowedContentLength, for IIS, in bytes --> 
         <requestLimits maxAllowedContentLength="15728640" ></requestLimits>
      </requestFiltering> 
   </security>
</system.webServer>

Enlace de referencia MSDN : https://msdn.microsoft.com/en-us/library/e1f13641 (VS.80).aspx

 56
Author: Malik Khalil,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-05-27 05:47:01

Creo en esta línea en la web.config establecerá el tamaño máximo de carga:

<system.web>

        <httpRuntime maxRequestLength="600000"/>
</system.web>
 14
Author: ben,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2008-11-13 22:56:07

Para un límite máximo de 2 Gb, en su aplicación web.config:

<system.web>
  <compilation debug="true" targetFramework="4.5" />
  <httpRuntime targetFramework="4.5" maxRequestLength="2147483647" executionTimeout="1600" requestLengthDiskThreshold="2147483647" />
</system.web>

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="2147483647" />
    </requestFiltering>
  </security>
</system.webServer>
 8
Author: cangosta,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-17 16:15:19

Si es windows 2003 / IIS 6.0, echa un vistazo a AspMaxRequestEntityAllowed = "204800" en el archivo metabase.xml ubicado en la carpeta C:\windows\system32\inetsrv\

El valor predeterminado de "204800" (~205Kb) es en mi opinión demasiado bajo para la mayoría de los usuarios. Simplemente cambia el valor a lo que crees que debería ser max.

Si no puede guardar el archivo después de editarlo, debe detener el servidor ISS o habilitar el servidor para permitir la edición del archivo:

Texto alternativo http://blogs.itmaskinen.se/image.axd?picture=WindowsLiveWriter/Request.BinaryReadFailedwindows2003IIS.0_BC5A/image_2.png

Editar: No he leído correctamente la pregunta (cómo configurar el maxrequest en webconfig). Pero esta informatin puede ser de interrest para otras personas, muchas personas que mueven sus sitios de win2000-server a win2003 y tenían una función de carga de trabajo y de repente recibió la Solicitud .BinaryRead Failed el error tendrá uso de él. Así que dejo la respuesta aquí.

 7
Author: Stefan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2008-11-13 23:38:05

Tengo el mismo problema en un servidor win 2008 IIS, he resuelto el problema añadiendo esta configuración en la web.config:

<system.web>
    <httpRuntime executionTimeout="3600" maxRequestLength="102400" 
     appRequestQueueLimit="100" requestValidationMode="2.0"
     requestLengthDiskThreshold="10024000"/>
</system.web>

El requestLengthDiskThreshold por defecto es de 80000 bytes por lo que es demasiado pequeño para mi aplicación. requestLengthDiskThreshold se mide en bytes y maxRequestLength se expresa en Kbytes.

El problema está presente si la aplicación está utilizando un componente de servidor System.Web.UI.HtmlControls.HtmlInputFile. El aumento de la requestLengthDiskThreshold es necesario resolver se.

 4
Author: Max Zerbini,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-18 15:44:31

Si está utilizando Framework 4.6

<httpRuntime targetFramework="4.6.1" requestValidationMode="2.0" maxRequestLength="10485760"  />
 3
Author: mbadeveloper,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-27 14:37:54

Puede escribir ese bloque de código en la web de su aplicación.archivo de configuración.

<httpRuntime maxRequestLength="2048576000" />
<sessionState timeout="3600"  />

Al escribir ese código, puede cargar un archivo más grande que ahora

 2
Author: user3683243,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-05-28 11:19:19

Sé que es una vieja pregunta.

Así que esto es lo que tienes que hacer:

En tu web.archivo de configuración, agregue esto en:

    <!-- 3GB Files / in kilobyte (3072*1024) -->
    <httpRuntime targetFramework="4.5" maxRequestLength="3145728"/>

Y esto bajo

<security>
    <requestFiltering>

      <!-- 3GB Files / in byte (3072*1024*1024) -->
      <requestLimits maxAllowedContentLength="3221225472" />

    </requestFiltering>
</security>

Puedes ver en el comentario cómo funciona esto. En uno necesita tener el sie en bytes y en el otro en kilobytes. Espero que eso ayude.

 2
Author: damir,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-20 12:19:08

Si utiliza sharepoint, también debe configurar el tamaño máximo con Herramientas Administrativas: kb925083

 0
Author: Quiz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-01-17 10:42:49

Tengo una entrada de blog sobre cómo aumentar el tamaño del archivo para el control de carga asp.

Del post:

De forma predeterminada, el control FileUpload permite cargar un máximo de 4MB de archivo y la ejecución el tiempo de espera es de 110 segundos. Estas propiedades se pueden cambiar desde la web.sección httpRuntime del archivo de configuración. La propiedad maxRequestLength determina el tamaño máximo de archivo que se puede cargar. El La propiedad executionTimeout determina el tiempo máximo para la ejecución.

 0
Author: sk1900,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-04-03 01:31:39

Si funciona en su máquina local y no funciona después de la implementación en IIS (usé Windows Server 2008 R2), tengo una solución.

Abrir IIS (inetmgr) Ir a su sitio web A la derecha ir al Contenido (Filtrado de solicitudes) Ir a Editar Configuración de Funciones Cambiar el tamaño máximo de contenido como (Bytes requeridos) Esto funcionará. También puede tomar ayuda de siguiente hilo http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits

 0
Author: Rahat Ali,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-03-19 10:20:40

El tamaño máximo del archivo se puede restringir a un solo controlador MVC o incluso a una Acción.
web.la etiqueta config se puede usar para esto:

<location path="YourAreaName/YourControllerName>/YourActionName>">
  <system.web>
    <!-- 15MB maxRequestLength for asp.net, in KB 15360 -->
    <httpRuntime maxRequestLength="15360" />
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
        <!-- 15MB maxAllowedContentLength, for IIS, in bytes 15728640 -->
        <requestLimits maxAllowedContentLength="15728640" />
      </requestFiltering>
    </security>
  </system.webServer>
</location>

O puede agregar estas entradas en la propia web del área.config.

 0
Author: Martin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-10-05 18:03:45