关于在Windwos2008(IIS7)下上传大文件的配置问题

做了一个系统,原来在windows2003下运行都正常,但在wnidow2008下无法上传大文件!

经过多日的研究,发现问题所在。

 

如何在IIS7设置ASP上传下载文件的大小
一、打开IIS7管理器

    选择internet 信息服务(IIS)管理器,在IIS管理器中找到对应的站点,双击asp图标,然后找到限制属性节点下面的:响应最大缓冲 和最大请求实体。修改这两个值为需要的值即可。

 

 

当上传一个超过30M的文件时,服务器会重定向至404.13页面,报错如下:

HTTP Error 404.13 - Not Found

The request filtering module is configured to deny a request that exceeds the request content length.

这是由于服务器限制了所能上传文件的最大值。其值在configuration/system.webServer/security/requestFiltering/requestLimits@maxAllowedContentLength setting in the applicationhost.config or web.config file. 中定义。

查看C:/Windows/System32/inetsrv/config目录下的applicationhost.config,可以在system.webServer/security/requestFiltering/中找到requestLimits设置项,若没有,则可以自行添加如下:(这里maxAllowedContentLength的单位为bytes。)

<system.webServer>
   <security>
       <requestFiltering>
              <requestLimits maxAllowedContentLength="40000000" />
       </requestFiltering>
   <security>
<system.webServer>

也可以使用命令行模式修改applicationhost.config为:

%windir%/system32/inetsrv/appcmd set config -section:requestFiltering -requestLimits.maxAllowedContentLength:40000000

经过这个设置后,服务器对上传文件的大小限制将变为40000000bytes了。当然,这个设置是服务器级别的,如果你想在某个站点或者某个应用上限制大小,也可以通过以相同方式进行设置,只不过这次设置的是站点内的Web.config

但是你要进行此项修改,要确保applicationhost.config中对该项修改的权限已经放开。可通过如下设置进行更改:

modify the overrideModeDefault from "Deny" to "Allow" like so:

<sectionGroup name="system.webServer">
     <section name="requestFiltering" overrideModeDefault="Allow" />
</sectionGroup>

确认修改过applicationhost.config中上述设置以后,再进行如下设置。

找到应用的Web.config,按上述进行修改:

<system.webServer>
   <security>
       <requestFiltering>
              <requestLimits maxAllowedContentLength="40000000" />
       </requestFiltering>
   <security>
<system.webServer>

或者你也可以通过命令行的形式:

%windir%/system32/inetsrv/appcmd set config "Default Web Site/<your app>" -section:requestFiltering -requestLimits.maxAllowedContentLength:40000000

这样,你就能针对某个站点的某个应用进行设置。

 

但是开发人员是在Web.Config中进行了如下设置:

<system.web>

<httpRuntime maxRequestLength="40960" appRequestQueueLimit="100" useFullyQualifiedRedirectUrl="true" executionTimeout="120" />

</system.web>

这里的maxRequestLengthMSDN介绍:Gets or sets the maximum request size. The maximum request size in kilobytes. The default size is 4096 KB (4 MB).

The MaxRequestLength property specifies the limit for the buffering threshold of the input stream. For example, this limit can be used to prevent denial of service attacks(拒绝服务攻击) that are caused by users who post large files to the server.

The value assigned to this property should be greater or equal to value assigned to the RequestLengthDiskThreshold property.

但是开发人员的这个设置好像是不起作用的。他们在这里,限制最大请求长度为40MB,超时为120s

下次再看一下具体这个设置是用来做什么的。

-------------------------

现在明白了。这个是用来设置单个请求的最大长度。比如EmailTicket中若设置maxRequestLength30MmaxAllowedContentLength40M,

然后在Reply Email时,选择了一个35M的附件,在点击Save as Draft的时候,这个请求的长度大概会有35M,这个已经超过了maxRequestLength。此时请求就会报错了,结果是黄页:

Server Error in '/emailticket' Application.


Maximum request length exceeded.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Maximum request length exceeded.

所以,最好是maxRequestLengthmaxAllowedContentLength设置为一致的值。

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值