我有一个窗体,除了一个文件上传在ASP.NET。我需要将最大上传大小增加到默认的4 MB以上。

我发现在msdn的某些地方引用了下面的代码。

[ConfigurationPropertyAttribute("maxRequestLength", DefaultValue = )]

没有任何参考文献真正描述了如何使用它,我已经尝试了几次,但都没有成功。我只想为要求上传文件的某些页面修改此属性。

走这条路对吗?我怎么使用这个呢?


当前回答

对于iis7 +,除了添加httpRuntime maxRequestLength设置外,还需要添加:

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

或者在IIS(7)中:

选择您要启用接受大文件上传的网站。 在主窗口双击“请求过滤” 选择“编辑功能设置” 修改“最大允许内容长度(字节)”

其他回答

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

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

requestLengthDiskThreshold默认为80000字节,因此对于我的应用程序来说太小了。requestLengthDiskThreshold以字节为单位,maxRequestLength以Kbytes为单位。

如果应用程序使用System.Web.UI.HtmlControls.HtmlInputFile服务器组件,就会出现这个问题。需要增加requestLengthDiskThreshold来解决这个问题。

对于2 GB的最大限制,在你的应用程序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>

如果你使用的是Framework 4.6

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

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

<system.web>

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

如果你使用sharepoint,你也应该在管理工具中配置最大大小: kb925083