如何在ASP.NET中增加最大上传文件大小?

时间:2022-12-09 10:10:24

I have a form that excepts a file upload in ASP.NET. I need to increase the max upload size to above the 4 MB default.

我有一个表单,除了在ASP.NET中上传的文件。我需要增加最大上传大小超过4 MB的默认值。

I have found in certain places referencing the below code at msdn.

我在msdn的某些地方找到了下面的代码。

[ConfigurationPropertyAttribute("maxRequestLength", DefaultValue = )]

None of the references actually describe how to use it, and I have tried several things with no success. I only want to modify this attribute for certain pages that are asking for file upload.

实际上没有任何参考文献描述了如何使用它,我尝试了好几种方法都没有成功。我只想修改某些页面的属性,这些页面要求文件上传。

Is this the correct route to take? And how do I use this?

这是正确的路线吗?我怎么用这个呢?

13 个解决方案

#1


333  

This setting goes in your web.config file. It affects the entire application, though... I don't think you can set it per page.

这个设置进入你的web。配置文件。它影响整个应用程序,但是……我认为你不能把它设置为每页。

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

"xxx" is in KB. The default is 4096 (= 4 MB).

“xxx”KB。默认值是4096 (= 4 MB)。

#2


143  

For IIS 7+, as well as adding the httpRuntime maxRequestLength setting you also need to add:

对于IIS 7+,除了添加httpRuntime maxRequestLength设置外,还需要添加以下设置:

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

Or in IIS (7):

或者在IIS(7):

  • Select the website you want enable to accept large file uploads.
  • 选择要启用的网站以接受大文件上传。
  • In the main window double click 'Request filtering'
  • 在主窗口中双击“请求过滤”
  • Select "Edit Feature Settings"
  • 选择“编辑功能设置”
  • Modify the "Maximum allowed content length (bytes)"
  • 修改“允许的最大内容长度(字节)”

#3


51  

To increase uploading file's size limit we have two ways

为了增加上传文件的大小限制,我们有两种方法

1. IIS6 or lower

1。IIS6中或更低

By default, in ASP.Net the maximum size of a file to be uploaded to the server is around 4MB. This value can be increased by modifying the maxRequestLength attribute in web.config.

默认情况下,在ASP。上传至服务器的文件的最大大小约为4MB。可以通过修改web.config中的maxRequestLength属性来增加这个值。

Remember : maxRequestLenght is in KB

记住:maxRequestLenght位于KB中

Example: if you want to restrict uploads to 15MB, set maxRequestLength to “15360” (15 x 1024).

示例:如果希望将上传限制为15MB,请将maxRequestLength设置为“15360”(15 x 1024)。

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

2. IIS7 or higher

2。IIS7或更高

A slight different way used here to upload files.IIS7 has introduced request filtering module.Which executed before ASP.Net.Means the way pipeline works is that the IIS value(maxAllowedContentLength) checked first then ASP.NET value(maxRequestLength) is checked.The maxAllowedContentLength attribute defaults to 28.61 MB.This value can be increased by modifying both attribute in same web.config.

这里使用一种稍微不同的方式来上传文件。IIS7引入了请求过滤模块。之前执行ASP.Net。表示管道工作的方式是首先检查IIS值(maxAllowedContentLength)。净值(maxRequestLength)检查。maxAllowedContentLength属性默认为28.61 mb .通过在同一个web.config中修改这两个属性,可以增加这个值。

Remember : maxAllowedContentLength is in bytes

记住:maxAllowedContentLength是以字节为单位的

Example : if you want to restrict uploads to 15MB, set maxRequestLength to “15360” and maxAllowedContentLength to "15728640" (15 x 1024 x 1024).

示例:如果希望将上传限制为15MB,请将maxRequestLength设置为“15360”,将maxAllowedContentLength设置为“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>

MSDN Reference link : https://msdn.microsoft.com/en-us/library/e1f13641(VS.80).aspx

MSDN参考链接:https://msdn.microsoft.com/en-us/library/e1f13641(VS.80).aspx

#4


14  

I believe this line in the web.config will set the max upload size:

我相信网络上的这条线。配置将设置最大上传大小:

<system.web>

        <httpRuntime maxRequestLength="600000"/>
</system.web>

#5


7  

If its windows 2003 / IIS 6.0 then check out AspMaxRequestEntityAllowed = "204800" in the file metabase.xml located in folder C:\windows\system32\inetsrv\

如果它的windows 2003 / iis6.0,那么请在文件metabase中检查AspMaxRequestEntityAllowed =“204800”。位于文件夹C中的xml:\windows\system32\inetsrv\

The default value of "204800" (~205Kb) is in my opinion too low for most users. Just change the value to what you think should be max.

“204800”(~205Kb)的默认值在我看来对大多数用户来说太低了。只要把值改成你认为的最大值。

If you cant save the file after editing it you have to either stop the ISS-server or enable the server to allow editing of the file:

如果你不能在编辑后保存文件,你必须停止ISS-server或使服务器允许编辑文件:

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

alt文本http://blogs.itmaskinen.se/image.axd?picture=WindowsLiveWriter/Request.BinaryReadFailedwindows2003IIS.0_BC5A/image_2.png

Edit: I did not read the question correct (how to set the maxrequest in webconfig). But this informatin may be of interrest for other people, many people who move their sites from win2000-server to win2003 and had a working upload-function and suddenly got the Request.BinaryRead Failed error will have use of it. So I leave the answer here.

编辑:我没有正确阅读问题(如何在webconfig中设置maxrequest)。但是这个信息对其他人来说可能是相互交叉的,许多人将他们的站点从win2000-server移动到win2003并且有一个工作的上传功能,然后突然收到了请求。BinaryRead失败的错误将会使用它。我把答案留在这里。

#6


7  

for a 2Gb max limit, on your application web.config :

在您的应用程序web上,最大限制为2Gb。配置:

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

#7


4  

I've the same problem in a win 2008 IIS server, I've solved the problem adding this configuration in the web.config:

我在win2008 IIS服务器上遇到了同样的问题,我已经解决了在web.config中添加这个配置的问题:

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

The requestLengthDiskThreshold by default is 80000 bytes so it's too small for my application. requestLengthDiskThreshold is measured in bytes and maxRequestLength is expressed in Kbytes.

默认情况下requestLengthDiskThreshold为80000字节,因此对我的应用程序来说太小。requestLengthDiskThreshold以字节度量,而maxRequestLength以Kbytes表示。

The problem is present if the application is using a System.Web.UI.HtmlControls.HtmlInputFile server component. Increasing the requestLengthDiskThreshold is necessary to solve it.

如果应用程序使用system . web . ui . html控件,则会出现问题。HtmlInputFile服务器组件。提高requestLengthDiskThreshold是解决它的必要条件。

#8


2  

You can write that block of code in your application web.config file.

您可以在应用程序web中编写该代码块。配置文件。

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

By writing that code you can upload a larger file than now

通过编写代码,您可以上传比现在更大的文件。

#9


2  

I know it is an old question.

我知道这是个老问题。

So this is what you have to do:

这就是你要做的:

In you web.config file, add this in :

在你的web。配置文件,添加如下:

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

and this under

这下

<security>
    <requestFiltering>

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

    </requestFiltering>
</security>

You see in the comment how this works. In one you need to have the sie in bytes and in the other one in kilobytes. Hope that helps.

你可以在评论中看到这是如何运作的。其中一个需要以字节为单位,另一个需要以千字节为单位。希望有帮助。

#10


2  

If you are using Framework 4.6

如果您正在使用框架4.6

<httpRuntime targetFramework="4.6.1" requestValidationMode="2.0" maxRequestLength="10485760"  />

#11


0  

If you use sharepoint you should configure max size with Administrative Tools too: kb925083

如果您使用sharepoint,则应该使用管理工具来配置max的大小:kb925083。

#12


0  

I have a blog post on how to increase the file size for asp upload control.

我有一篇关于如何增加asp上传控件的文件大小的博文。

From the post:

职务:

By default, the FileUpload control allows a maximum of 4MB file to be uploaded and the execution timeout is 110 seconds. These properties can be changed from within the web.config file’s httpRuntime section. The maxRequestLength property determines the maximum file size that can be uploaded. The executionTimeout property determines the maximum time for execution.

默认情况下,FileUpload控件允许上传最多4MB的文件,执行超时为110秒。这些属性可以在web中更改。配置文件的httpRuntime部分。maxRequestLength属性确定可以上传的最大文件大小。executionTimeout属性确定执行的最大时间。

#13


0  

If it works in your local machine and does not work after deployment in IIS (i used Windows Server 2008 R2) i have a solution.

如果它在本地机器中工作,并且在IIS中部署后不工作(我使用Windows Server 2008 R2),我有一个解决方案。

Open IIS (inetmgr) Go to your website At right hand side go to Content (Request Filtering) Go to Edit Feature Settings Change maximum content size as (Bytes you required) This will work. You can also take help from following thread http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits

打开IIS (inetmgr)到你的网站,在右边进入内容(请求过滤)去编辑功能设置,改变最大的内容大小(你需要的字节)这将会起作用。您还可以从以下线程获得帮助:http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits。

#1


333  

This setting goes in your web.config file. It affects the entire application, though... I don't think you can set it per page.

这个设置进入你的web。配置文件。它影响整个应用程序,但是……我认为你不能把它设置为每页。

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

"xxx" is in KB. The default is 4096 (= 4 MB).

“xxx”KB。默认值是4096 (= 4 MB)。

#2


143  

For IIS 7+, as well as adding the httpRuntime maxRequestLength setting you also need to add:

对于IIS 7+,除了添加httpRuntime maxRequestLength设置外,还需要添加以下设置:

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

Or in IIS (7):

或者在IIS(7):

  • Select the website you want enable to accept large file uploads.
  • 选择要启用的网站以接受大文件上传。
  • In the main window double click 'Request filtering'
  • 在主窗口中双击“请求过滤”
  • Select "Edit Feature Settings"
  • 选择“编辑功能设置”
  • Modify the "Maximum allowed content length (bytes)"
  • 修改“允许的最大内容长度(字节)”

#3


51  

To increase uploading file's size limit we have two ways

为了增加上传文件的大小限制,我们有两种方法

1. IIS6 or lower

1。IIS6中或更低

By default, in ASP.Net the maximum size of a file to be uploaded to the server is around 4MB. This value can be increased by modifying the maxRequestLength attribute in web.config.

默认情况下,在ASP。上传至服务器的文件的最大大小约为4MB。可以通过修改web.config中的maxRequestLength属性来增加这个值。

Remember : maxRequestLenght is in KB

记住:maxRequestLenght位于KB中

Example: if you want to restrict uploads to 15MB, set maxRequestLength to “15360” (15 x 1024).

示例:如果希望将上传限制为15MB,请将maxRequestLength设置为“15360”(15 x 1024)。

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

2. IIS7 or higher

2。IIS7或更高

A slight different way used here to upload files.IIS7 has introduced request filtering module.Which executed before ASP.Net.Means the way pipeline works is that the IIS value(maxAllowedContentLength) checked first then ASP.NET value(maxRequestLength) is checked.The maxAllowedContentLength attribute defaults to 28.61 MB.This value can be increased by modifying both attribute in same web.config.

这里使用一种稍微不同的方式来上传文件。IIS7引入了请求过滤模块。之前执行ASP.Net。表示管道工作的方式是首先检查IIS值(maxAllowedContentLength)。净值(maxRequestLength)检查。maxAllowedContentLength属性默认为28.61 mb .通过在同一个web.config中修改这两个属性,可以增加这个值。

Remember : maxAllowedContentLength is in bytes

记住:maxAllowedContentLength是以字节为单位的

Example : if you want to restrict uploads to 15MB, set maxRequestLength to “15360” and maxAllowedContentLength to "15728640" (15 x 1024 x 1024).

示例:如果希望将上传限制为15MB,请将maxRequestLength设置为“15360”,将maxAllowedContentLength设置为“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>

MSDN Reference link : https://msdn.microsoft.com/en-us/library/e1f13641(VS.80).aspx

MSDN参考链接:https://msdn.microsoft.com/en-us/library/e1f13641(VS.80).aspx

#4


14  

I believe this line in the web.config will set the max upload size:

我相信网络上的这条线。配置将设置最大上传大小:

<system.web>

        <httpRuntime maxRequestLength="600000"/>
</system.web>

#5


7  

If its windows 2003 / IIS 6.0 then check out AspMaxRequestEntityAllowed = "204800" in the file metabase.xml located in folder C:\windows\system32\inetsrv\

如果它的windows 2003 / iis6.0,那么请在文件metabase中检查AspMaxRequestEntityAllowed =“204800”。位于文件夹C中的xml:\windows\system32\inetsrv\

The default value of "204800" (~205Kb) is in my opinion too low for most users. Just change the value to what you think should be max.

“204800”(~205Kb)的默认值在我看来对大多数用户来说太低了。只要把值改成你认为的最大值。

If you cant save the file after editing it you have to either stop the ISS-server or enable the server to allow editing of the file:

如果你不能在编辑后保存文件,你必须停止ISS-server或使服务器允许编辑文件:

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

alt文本http://blogs.itmaskinen.se/image.axd?picture=WindowsLiveWriter/Request.BinaryReadFailedwindows2003IIS.0_BC5A/image_2.png

Edit: I did not read the question correct (how to set the maxrequest in webconfig). But this informatin may be of interrest for other people, many people who move their sites from win2000-server to win2003 and had a working upload-function and suddenly got the Request.BinaryRead Failed error will have use of it. So I leave the answer here.

编辑:我没有正确阅读问题(如何在webconfig中设置maxrequest)。但是这个信息对其他人来说可能是相互交叉的,许多人将他们的站点从win2000-server移动到win2003并且有一个工作的上传功能,然后突然收到了请求。BinaryRead失败的错误将会使用它。我把答案留在这里。

#6


7  

for a 2Gb max limit, on your application web.config :

在您的应用程序web上,最大限制为2Gb。配置:

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

#7


4  

I've the same problem in a win 2008 IIS server, I've solved the problem adding this configuration in the web.config:

我在win2008 IIS服务器上遇到了同样的问题,我已经解决了在web.config中添加这个配置的问题:

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

The requestLengthDiskThreshold by default is 80000 bytes so it's too small for my application. requestLengthDiskThreshold is measured in bytes and maxRequestLength is expressed in Kbytes.

默认情况下requestLengthDiskThreshold为80000字节,因此对我的应用程序来说太小。requestLengthDiskThreshold以字节度量,而maxRequestLength以Kbytes表示。

The problem is present if the application is using a System.Web.UI.HtmlControls.HtmlInputFile server component. Increasing the requestLengthDiskThreshold is necessary to solve it.

如果应用程序使用system . web . ui . html控件,则会出现问题。HtmlInputFile服务器组件。提高requestLengthDiskThreshold是解决它的必要条件。

#8


2  

You can write that block of code in your application web.config file.

您可以在应用程序web中编写该代码块。配置文件。

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

By writing that code you can upload a larger file than now

通过编写代码,您可以上传比现在更大的文件。

#9


2  

I know it is an old question.

我知道这是个老问题。

So this is what you have to do:

这就是你要做的:

In you web.config file, add this in :

在你的web。配置文件,添加如下:

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

and this under

这下

<security>
    <requestFiltering>

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

    </requestFiltering>
</security>

You see in the comment how this works. In one you need to have the sie in bytes and in the other one in kilobytes. Hope that helps.

你可以在评论中看到这是如何运作的。其中一个需要以字节为单位,另一个需要以千字节为单位。希望有帮助。

#10


2  

If you are using Framework 4.6

如果您正在使用框架4.6

<httpRuntime targetFramework="4.6.1" requestValidationMode="2.0" maxRequestLength="10485760"  />

#11


0  

If you use sharepoint you should configure max size with Administrative Tools too: kb925083

如果您使用sharepoint,则应该使用管理工具来配置max的大小:kb925083。

#12


0  

I have a blog post on how to increase the file size for asp upload control.

我有一篇关于如何增加asp上传控件的文件大小的博文。

From the post:

职务:

By default, the FileUpload control allows a maximum of 4MB file to be uploaded and the execution timeout is 110 seconds. These properties can be changed from within the web.config file’s httpRuntime section. The maxRequestLength property determines the maximum file size that can be uploaded. The executionTimeout property determines the maximum time for execution.

默认情况下,FileUpload控件允许上传最多4MB的文件,执行超时为110秒。这些属性可以在web中更改。配置文件的httpRuntime部分。maxRequestLength属性确定可以上传的最大文件大小。executionTimeout属性确定执行的最大时间。

#13


0  

If it works in your local machine and does not work after deployment in IIS (i used Windows Server 2008 R2) i have a solution.

如果它在本地机器中工作,并且在IIS中部署后不工作(我使用Windows Server 2008 R2),我有一个解决方案。

Open IIS (inetmgr) Go to your website At right hand side go to Content (Request Filtering) Go to Edit Feature Settings Change maximum content size as (Bytes you required) This will work. You can also take help from following thread http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits

打开IIS (inetmgr)到你的网站,在右边进入内容(请求过滤)去编辑功能设置,改变最大的内容大小(你需要的字节)这将会起作用。您还可以从以下线程获得帮助:http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits。