ASP.NET网站大附件上传配置

NET应用程序上传文件大小限制并非都是IIS的原因,也有可能是应用程序自身设置造成的,在使用过程中一定要区分开来,这样才能做到正确的设置。

1..NET应用程序限制上传文件大小:超过了最大请求长度

这类错误就是由于应用程序自身设置造成的。只需在web.config的<system.web>节加入以下内容即可:

<configuration>
  <system.web>
    <!-- maxRequestLength单位KB,executionTimeout单位是秒 -->
    <httpRuntime maxRequestLength="51200" useFullyQualifiedRedirectUrl="true" executionTimeout="43200"/>
  </system.web>
</configuration>

 

2.IIS限制上传文件大小:请求筛选模块被配置为拒绝超过请求内容长度的请求

这类错误是由于IIS7.0限制上传文件大小为30000000字节(约28.6M)造成的。打开C:\Windows\System32\inetsrv\config\schema\IIS_schema.xml,找到如下内容:

<element name="requestLimits">
   <attribute name="maxAllowedContentLength" type="uint" defaultValue="30000000" />
   <attribute name="maxUrl" type="uint" defaultValue="4096" />
   <attribute name="maxQueryString" type="uint" defaultValue="2048" />
   <element name="headerLimits">
     <collection addElement="add" clearElement="clear" removeElement="remove" >
       <attribute name="header" type="string" required="true" isUniqueKey="true" validationType="nonEmptyString" />
       <attribute name="sizeLimit" type="uint" required="true" />
     </collection>
   </element>
</element>

将maxAllowedContentLength的默认值修改成合适大小即可,单位为字节。

IIS_schema.xml默认是无法修改的,即使是系统管理员也不行,必需修改下权限,再去掉其只读属性才可修改。

直接点击"编辑"按钮你会发现权限是不能修改的,还得先做如下操作:
1).点击"高级"按钮进入高级安全设置界面;
2).切换到"所有者"选项卡,点"编辑"按钮,选中Administrators后确定;
然后可以在"安全"选项卡上点击"编辑"按钮,给Administrators增加修改和写入权限了,再去掉IIS_schema.xml只读属性,系统管理员就可以修改文件了。

 

(感谢原作者提供的解决方案,亲测可用,很好很强大。)

posted @ 2012-10-25 16:50  DannyLi  阅读(354)  评论(0编辑  收藏  举报