IIS7.0上传文件限制29M解决方法

来源:互联网 发布:平板如何删除软件 编辑:程序博客网 时间:2024/06/06 16:28

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

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

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

 <httpRuntime maxRequestLength="102400" executionTimeout="600" />


说明:maxRequestLength单位KB,executionTimeout单位是秒。

 

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

 

这类错误是由于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属性中的defaultValue值修改成合适大小即可,单位为字节。

3. 其他说明

IIS_schema.xml默认是无法修改的,即使是系统管理员也不行,必需修改下权限,再去掉其只读属性才可修改;上图为IIS_schema.xml默认权限,直接点击"编辑"按钮你会发现权限是不能修改的,还得先做如下操作:
1).点击"高级"按钮进入高级安全设置界面;
2).切换到"所有者"选项卡,点"编辑"按钮,选中Administrators后确定;

现在可以在"安全"选项卡上点击"编辑"按钮,给Administrators增加修改和写入权限了,再去掉IIS_schema.xml只读属性,系统管理员就可以修改文件了。