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

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

[ConfigurationPropertyAttribute("maxRequestLength", DefaultValue = )]

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

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


当前回答

我在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来解决这个问题。

其他回答

你可以在你的web应用程序中编写这段代码。配置文件。

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

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

最大文件大小可以限制为单个MVC控制器甚至一个动作。 网络。Config <location>标签可以用于此:

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

或者你可以在区域自己的web.config中添加这些条目。

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

以下是原文:

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

我在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来解决这个问题。

我知道这是个老问题。

这就是你要做的:

在你的网上。配置文件,在<system.web>:

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

在<system.webServer>:

<security>
    <requestFiltering>

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

    </requestFiltering>
</security>

你可以在评论中看到它是如何工作的。在其中一个中,sie的单位是字节,在另一个中,sie的单位是千字节。希望这能有所帮助。