Sac*_*hag 1902
如果您使用IIS来托管应用程序,则默认上载文件大小为4MB.要增加它,请在web.config中使用以下部分 -
<configuration>
<system.web>
<httpRuntime maxRequestLength="1048576" />
</system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)
对于IIS7及更高版本,您还需要添加以下行:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
注意:
maxRequestLength
以千字节为单位maxAllowedContentLength
以字节为单位 这就是为什么这个配置示例中的值不同的原因.(两者相当于1 GB)
Kar*_*arl 542
我认为这里没有提到它,但为了使其工作,我必须在web.config中提供这两个值:
在 system.web
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
Run Code Online (Sandbox Code Playgroud)
并在 system.webServer
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
Run Code Online (Sandbox Code Playgroud)
重要提示:这两个值必须匹配.在这种情况下,我的最大上传量为1024兆字节.
maxRequestLength有1048576 KILOBYTES,maxAllowedContentLength有1073741824 BYTES.
我知道这很明显,但很容易被忽视.
Nic*_*cht 192
值得注意的是,您可能希望将此更改限制为您希望用于上载的URL,而不是整个站点.
<location path="Documents/Upload">
<system.web>
<!-- 50MB in kilobytes, default is 4096 or 4MB-->
<httpRuntime maxRequestLength="51200" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<!-- 50MB in bytes, default is 30000000 or approx. 28.6102 Mb-->
<requestLimits maxAllowedContentLength="52428800" />
</requestFiltering>
</security>
</system.webServer>
</location>
Run Code Online (Sandbox Code Playgroud)
Ser*_*ltz 43
并且万一有人正在寻找一种方法来处理这个异常并向用户显示一个有意义的解释(例如"你上传的文件太大了"):
//Global.asax
private void Application_Error(object sender, EventArgs e)
{
var ex = Server.GetLastError();
var httpException = ex as HttpException ?? ex.InnerException as HttpException;
if(httpException == null) return;
if(httpException.WebEventCode == WebEventCodes.RuntimeErrorPostTooLarge)
{
//handle the error
Response.Write("Too big a file, dude"); //for example
}
}
Run Code Online (Sandbox Code Playgroud)
(需要ASP.NET 4或更高版本)
Dav*_*ave 28
默认情况下,最大请求大小为4mb(4096 KB)
这在此解释:http://support.microsoft.com/default.aspx?scid = kb; EN-US; 2955626
上面的文章还解释了如何解决这个问题:)
Ser*_*sov 20
如果您无法更新配置文件但控制处理文件上载使用的代码HttpContext.Current.Request.GetBufferlessInputStream(true)
.
参数的true
值disableMaxRequestLength
告诉框架忽略已配置的请求限制.
有关详细说明,请访问https://msdn.microsoft.com/en-us/library/hh195568(v=vs.110).aspx
ema*_*ema 19
There's an element in web.config to configure the max size of the uploaded file:
<httpRuntime
maxRequestLength="1048576"
/>
Run Code Online (Sandbox Code Playgroud)
在一个地方总结所有答案:
<system.web>
<httpRuntime targetFramework="4.5.2" maxRequestLength="1048576"/>
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
规则:
笔记:
更多信息MSDN
maxRequestLength(以KB为单位的长度)此处为ex.我拿1024(1MB)maxAllowedContentLength(字节长度)应该与你的maxRequestLength(1048576字节= 1MB)相同.
<system.web>
<httpRuntime maxRequestLength="1024" executionTimeout="3600" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1048576"/>
</requestFiltering>
</security>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
如果您有请求转到站点中的应用程序,请确保在根web.config中设置maxRequestLength.应用程序的web.config中的maxRequestLength似乎被忽略.
归档时间: |
|
查看次数: |
704245 次 |
最近记录: |