我有一个窗体,除了一个文件上传在ASP.NET。我需要将最大上传大小增加到默认的4 MB以上。
我发现在某些地方引用下面的代码msdn。
[ConfigurationPropertyAttribute("maxRequestLength", DefaultValue = )]
没有任何参考文献真正描述了如何使用它,我已经尝试了几次,但都没有成功。我只想为要求上传文件的某些页面修改此属性。
走这条路对吗?我怎么使用这个呢?
如果是windows 2003 / IIS 6.0,那么检查位于C:\windows\system32\inetsrv\的metabase.xml文件中的AspMaxRequestEntityAllowed = "204800"
默认值“204800”(~205Kb)在我看来对于大多数用户来说太低了。只需将值更改为您认为应该是max的值。
如果你不能保存文件后编辑它,你必须停止ISS-server或使服务器允许编辑文件:
编辑:我没有阅读正确的问题(如何设置webconfig中的maxrequest)。但是这个信息可能会对其他人感兴趣,许多人将他们的网站从win2000-server移动到win2003,并且有一个工作的上传功能,突然得到请求。BinaryRead失败错误将会使用它。所以我把答案留在这里。
我相信Web.config中的这一行将设置最大上传大小:
Web.config
<system.web> <httpRuntime maxRequestLength="600000"/> </system.web>
这个设置在你的网页中。配置文件。不过,它会影响整个应用程序……我认为你不能每页设置。
<configuration> <system.web> <httpRuntime maxRequestLength="xxx" /> </system.web> </configuration>
xxx的单位为KB。默认值是4096 (= 4 MB)。
我在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.UI.HtmlControls.HtmlInputFile
对于iis7 +,除了添加httpRuntime maxRequestLength设置外,还需要添加:
<system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="52428800" /> <!--50MB--> </requestFiltering> </security> </system.webServer>
或者在IIS(7)中:
选择您要启用接受大文件上传的网站。 在主窗口双击“请求过滤” 选择“编辑功能设置” 修改“最大允许内容长度(字节)”
我有一篇关于如何增加asp上传控制的文件大小的博客文章。
以下是原文:
默认情况下,FileUpload控件允许上传和执行的文件的最大容量为4MB 超时时间为110秒。这些属性可以从web内部更改。配置文件的httpRuntime部分。maxRequestLength属性决定了可以上传的最大文件大小。的 . executionTimeout属性决定最大执行时间
默认情况下,FileUpload控件允许上传和执行的文件的最大容量为4MB 超时时间为110秒。这些属性可以从web内部更改。配置文件的httpRuntime部分。maxRequestLength属性决定了可以上传的最大文件大小。的
你可以在你的web应用程序中编写这段代码。配置文件。
<httpRuntime maxRequestLength="2048576000" /> <sessionState timeout="3600" />
通过编写这些代码,您可以上传一个比现在更大的文件
如果它在您的本地机器上工作,在IIS(我使用Windows Server 2008 R2)部署后不工作,我有一个解决方案。
打开IIS (inetmgr) 去你的网站 在右边选择内容(请求过滤) 进入“编辑功能设置” 将最大内容大小更改为(所需字节数) 这是可行的。 你也可以从下面的帖子中得到帮助 http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits < / p >
我知道这是个老问题。
这就是你要做的:
在你的网上。在<system.web>中添加:
<system.web>
<!-- 3GB Files / in kilobyte (3072*1024) --> <httpRuntime targetFramework="4.5" maxRequestLength="3145728"/>
和<system.webServer>下的this:
<system.webServer>
<security> <requestFiltering> <!-- 3GB Files / in byte (3072*1024*1024) --> <requestLimits maxAllowedContentLength="3221225472" /> </requestFiltering> </security>
你可以在评论中看到它是如何工作的。在其中一个中,sie的单位是字节,在另一个中,sie的单位是千字节。希望这能有所帮助。
对于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>
要增加上传文件的大小限制,我们有两种方法
默认情况下,在ASP。上传到服务器的文件的最大大小为 4 mb左右。属性可以增加该值 maxRequestLength. config中的>属性。 记住:maxrequestlengt的单位是KB
默认情况下,在ASP。上传到服务器的文件的最大大小为 4 mb左右。属性可以增加该值 maxRequestLength. config中的>属性。
记住:maxrequestlengt的单位是KB
例子:如果你想限制上传到15MB,设置maxRequestLength为“15360”(15 x 1024)。
<system.web> <!-- maxRequestLength for asp.net, in KB --> <httpRuntime maxRequestLength="15360" ></httpRuntime> </system.web>
这里上传文件的方式略有不同。IIS7已经 介绍了请求过滤模块。之前执行过 意思是流水线的工作方式是IIS 首先检查value(maxAllowedContentLength),然后检查ASP. value。网 value(maxRequestLength)被检查。的maxAllowedContentLength 属性默认为28.61 MB。此值可以通过 在同一个. config中修改两个属性 记住:maxAllowedContentLength以字节为单位
记住:maxAllowedContentLength以字节为单位
例子:如果你想限制上传到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>
__abc0: __abc1
如果你使用的是Framework 4.6
<httpRuntime targetFramework="4.6.1" requestValidationMode="2.0" maxRequestLength="10485760" />
<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中添加这些条目。