做C#项目中,需要用到文件上传的,但是上传文件相对较大时(20M以上)则会失败的,网上搜索下,找到可以用的方法,特此记录下,方便以后参考:
有时候我们需要限制上传文件的大小,那么可以参考下面的方法
方法1:
appcmd set config “My Site/MyApp” -section:requestFiltering -requestLimits.maxAllowedContentLength:104857600 -commitpath:apphost
在IIS服务器的命令行执行如上命令,注意修改上面的网站名称和上传文件大小
方法2:
在web.config中加入如下配置:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1048576000"></requestLimits>
</requestFiltering>
</security>
</system.webServer>
在IIS 6.0中设置文件上传大小的方法,就是配置如下节点:
<system.web>
<httpRuntime maxRequestLength="1048576" executionTimeout="600"/>
</system.web>
但在IIS7中,设置如上设置后,不管设置多大数值,最大上传了限制为30M.