IIS7 - 请求过滤模块配置为拒绝超过请求内容长度的请求

问题描述 投票:0回答:3

我想上传图像,它在我的机器上运行良好,但是当我将我的网站放在 IIS7 公共服务器上时,我无法上传任何内容。

错误

请求过滤模块被配置为拒绝以下请求: 超过请求内容长度。

最可能的原因

在Web服务器上配置请求过滤来拒绝请求 因为内容长度超过了配置的值。

你可以尝试的事情

验证配置/system.webServer/security/requestFiltering/requestLimits@maxAllowedContentLength 在 applicationhost.config 或 web.config 文件中设置。

Web.config 中的system.webServer

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
    <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="1048576" />
      </requestFiltering>
   </security>
  </system.webServer>

如您所见,我将 maxAllowedContentLength 设置为 1gb。重新启动我的网站,仍然出现此错误。我在我的文件系统上创建了一个

/uploads/
文件夹,它也应该在其中。不知道是什么原因导致此错误以及为什么我无法上传图像。

asp.net asp.net-mvc-3 iis iis-7
3个回答
50
投票
<configuration>
    <system.web>
        <httpRuntime maxRequestLength="1048576" />
    </system.web>
</configuration>

这里

对于IIS7及以上版本,还需要添加以下行:

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

3
投票

以下示例 Web.config 文件将配置 IIS 以拒绝“Content-type”标头长度大于 100 字节的 HTTP 请求的访问。

  <configuration>
   <system.webServer>
      <security>
         <requestFiltering>
            <requestLimits>
               <headerLimits>
                  <add header="Content-type" sizeLimit="100" />
               </headerLimits>
            </requestLimits>
         </requestFiltering>
      </security>
   </system.webServer>
</configuration>

来源:http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits


0
投票

我遇到了类似的问题,我通过更改 applicationhost.config 文件的 requestlimits maxAllowedContentLength ="40000000" 部分(位于“C:\Windows\System32\inetsr”)来解决

© www.soinside.com 2019 - 2024. All rights reserved.