Edd*_*die 229 .net c# asp.net file-upload
我有一个表单,除了ASP.NET中的文件上传.我需要将最大上传大小增加到4 MB以上.
我在某些地方发现在msdn上引用下面的代码.
[ConfigurationPropertyAttribute("maxRequestLength", DefaultValue = )]
Run Code Online (Sandbox Code Playgroud)
没有一个参考文献真正描述了如何使用它,我尝试了几件事但没有成功.我只想为要求文件上传的某些页面修改此属性.
这是正确的路线吗?我该如何使用它?
Eri*_*ger 396
此设置位于web.config文件中.它影响整个应用程序,但是......我不认为你可以在每页设置它.
<configuration>
<system.web>
<httpRuntime maxRequestLength="xxx" />
</system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)
"xxx"以KB为单位.默认值为4096(= 4 MB).
4im*_*ble 173
对于IIS 7+,以及添加httpRuntime maxRequestLength设置,您还需要添加:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="52428800" /> <!--50MB-->
</requestFiltering>
</security>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
或者在IIS(7)中:
- 选择要启用以接受大文件上载的网站.
- 在主窗口中双击"请求过滤"
- 选择"编辑功能设置"
- 修改"允许的最大内容长度(字节)"
Mal*_*lil 71
为了增加上传文件的大小限制,我们有两种方法
1. IIS6或更低版本
默认情况下,在ASP.Net中,要上载到服务器的文件的最大大小约为4MB.可以通过修改web.config中的maxRequestLength属性来增加此值 .
请记住:maxRequestLenght以KB为单位
示例:如果要将上载限制为15MB,请将maxRequestLength设置为"15360"(15 x 1024).
<system.web>
<!-- maxRequestLength for asp.net, in KB -->
<httpRuntime maxRequestLength="15360" ></httpRuntime>
</system.web>
Run Code Online (Sandbox Code Playgroud)
2. IIS7或更高版本
这里用来上传文件的方式略有不同.IIS7引入了请求过滤模块.在ASP.Net.Means之前执行管道工作的方式是先检查IIS值(maxAllowedContentLength)然后检查ASP.NET值(maxRequestLength). maxAllowedContentLength属性默认为28.61 MB.可以通过修改同一web.config中的两个属性来增加此值.
请记住: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>
Run Code Online (Sandbox Code Playgroud)
MSDN参考链接:https://msdn.microsoft.com/en-us/library/e1f13641(VS.80).aspx
ben*_*ben 17
我相信web.config中的这一行将设置最大上传大小:
<system.web>
<httpRuntime maxRequestLength="600000"/>
</system.web>
Run Code Online (Sandbox Code Playgroud)
can*_*sta 12
对于2Gb最大限制,在您的应用程序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>
Run Code Online (Sandbox Code Playgroud)
如果它的Windows 2003/IIS 6.0然后检查文件夹C:\ windows\system32\inetsrv\中的metabase.xml文件中的AspMaxRequestEntityAllowed ="204800"
对于大多数用户来说,默认值"204800"(~205Kb)对我来说太低了.只需将值更改为您认为应该最大的值.
如果在编辑后无法保存文件,则必须停止ISS服务器或启用服务器以允许编辑文件:

(来源:itmaskinen.se)
编辑:我没有正确阅读问题(如何在webconfig中设置maxrequest).但是这个信息可能对其他人有利,许多人将他们的网站从win2000-server移动到win2003并且有一个有效的上传功能,并突然得到Request.BinaryRead失败错误将使用它.所以我在这里留下答案.
我在 win 2008 IIS 服务器中遇到了同样的问题,我已经解决了在 web.config 中添加此配置的问题:
<system.web>
<httpRuntime executionTimeout="3600" maxRequestLength="102400"
appRequestQueueLimit="100" requestValidationMode="2.0"
requestLengthDiskThreshold="10024000"/>
</system.web>
Run Code Online (Sandbox Code Playgroud)
该requestLengthDiskThreshold默认为80000个字节,因此它太小了我的申请。requestLengthDiskThreshold 以字节为单位,maxRequestLength 以千字节表示。
如果应用程序使用System.Web.UI.HtmlControls.HtmlInputFile服务器组件,就会出现问题。需要增加 requestLengthDiskThreshold 来解决它。
我知道这是一个老问题。
所以这就是你必须做的:
在您的 web.config 文件中,添加以下内容<system.web>:
<!-- 3GB Files / in kilobyte (3072*1024) -->
<httpRuntime targetFramework="4.5" maxRequestLength="3145728"/>
Run Code Online (Sandbox Code Playgroud)
这在下面<system.webServer>:
<security>
<requestFiltering>
<!-- 3GB Files / in byte (3072*1024*1024) -->
<requestLimits maxAllowedContentLength="3221225472" />
</requestFiltering>
</security>
Run Code Online (Sandbox Code Playgroud)
您在评论中看到这是如何工作的。在一种情况下,您需要以字节为单位的 sie,而在另一种情况下,您需要以千字节为单位的 sie。希望有帮助。
小智 5
最大文件大小可以限制为单个 MVC 控制器甚至是一个操作。
web.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>
Run Code Online (Sandbox Code Playgroud)
或者您可以在区域自己的 web.config 中添加这些条目。