我有一个窗体,除了一个文件上传在ASP.NET。我需要将最大上传大小增加到默认的4 MB以上。
我发现在msdn的某些地方引用了下面的代码。
[ConfigurationPropertyAttribute("maxRequestLength", DefaultValue = )]
没有任何参考文献真正描述了如何使用它,我已经尝试了几次,但都没有成功。我只想为要求上传文件的某些页面修改此属性。
走这条路对吗?我怎么使用这个呢?
我有一个窗体,除了一个文件上传在ASP.NET。我需要将最大上传大小增加到默认的4 MB以上。
我发现在msdn的某些地方引用了下面的代码。
[ConfigurationPropertyAttribute("maxRequestLength", DefaultValue = )]
没有任何参考文献真正描述了如何使用它,我已经尝试了几次,但都没有成功。我只想为要求上传文件的某些页面修改此属性。
走这条路对吗?我怎么使用这个呢?
当前回答
如果你使用的是Framework 4.6
<httpRuntime targetFramework="4.6.1" requestValidationMode="2.0" maxRequestLength="10485760" />
其他回答
你可以在你的web应用程序中编写这段代码。配置文件。
<httpRuntime maxRequestLength="2048576000" />
<sessionState timeout="3600" />
通过编写这些代码,您可以上传一个比现在更大的文件
这个设置在你的网页中。配置文件。不过,它会影响整个应用程序……我认为你不能每页设置。
<configuration>
<system.web>
<httpRuntime maxRequestLength="xxx" />
</system.web>
</configuration>
xxx的单位为KB。默认值是4096 (= 4 MB)。
我相信网络上的这句话。配置将设置最大上传大小:
<system.web>
<httpRuntime maxRequestLength="600000"/>
</system.web>
对于iis7 +,除了添加httpRuntime maxRequestLength设置外,还需要添加:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="52428800" /> <!--50MB-->
</requestFiltering>
</security>
</system.webServer>
或者在IIS(7)中:
选择您要启用接受大文件上传的网站。 在主窗口双击“请求过滤” 选择“编辑功能设置” 修改“最大允许内容长度(字节)”
要增加上传文件的大小限制,我们有两种方法
1. IIS6或更低
默认情况下,在ASP。上传到服务器的文件的最大大小为 4 mb左右。属性可以增加该值 config中的maxRequestLength属性。 记住:maxrequestlengt的单位是KB
例如:如果你想限制上传15MB,设置maxRequestLength为“15360”(15 * 1024)。
<system.web>
<!-- maxRequestLength for asp.net, in KB -->
<httpRuntime maxRequestLength="15360" ></httpRuntime>
</system.web>
2. IIS7或更高
这里使用的上传文件的方式略有不同。IIS7已经 介绍了请求过滤模块。之前执行过 意思是流水线的工作方式是IIS value(maxAllowedContentLength)先检查,然后ASP。网 value(maxRequestLength)被检查。的maxAllowedContentLength 属性默认为28.61 mb。此值可以通过 在同一个web.config中修改两个属性。 记住:maxAllowedContentLength以字节为单位
例如:如果你想限制上传15MB,设置maxRequestLength为“15360”,maxAllowedContentLength为“15728640”(15 * 1024 * 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参考链接:https://msdn.microsoft.com/en-us/library/e1f13641(VS.80).aspx