【问题标题】:maxRequestLength for .Net 4.5.1 framework.Net 4.5.1 框架的 maxRequestLength
【发布时间】:2014-04-27 18:34:53
【问题描述】:

我想将 .Net framework 4.0 代码转换为 .Net framework 4.5。这基本上是一个文件上传相关的代码。现在我面临一些问题。 maxRequestLength 的最大值是多少? 我已经在我的 web.config 文件 中添加了这一行,但它不起作用并且错误代码是 0x800700b7

<system.web>
<httpRuntime maxRequestLength="102400" executionTimeout ="3600" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2880"/>
</authentication>
<pages>
  <namespaces>
    <add namespace="System.Web.Helpers"/>
    <add namespace="System.Web.Mvc"/>
    <add namespace="System.Web.Mvc.Ajax"/>
    <add namespace="System.Web.Mvc.Html"/>
    <add namespace="System.Web.Optimization"/>
    <add namespace="System.Web.Routing"/>
    <add namespace="System.Web.WebPages"/>
  </namespaces>
  </pages>
  <compilation debug="true"/>
  </system.web>
  <system.webServer>
  <validation validateIntegratedModeConfiguration="false"/>

   <security>  
  <requestFiltering>  
     <requestLimits maxAllowedContentLength="104857600" />  
  </requestFiltering>  
  </security> 

<handlers>
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"/>
  <remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." />
</handlers>

【问题讨论】:

    标签: asp.net-mvc


    【解决方案1】:

    如果您托管在 IIS 中,则需要两项设置:

    • ma​​xRequestLength - 用于 ASP.net(以 KB 为单位)
    • ma​​xAllowedContentLength - 用于 IIS(以字节为单位)

    示例配置:(这是针对 100MB 上传限制)

    <configuration>  
        <system.web>  
            <httpRuntime maxRequestLength="102400" executionTimeout="3600" />  
        </system.web>  
    </configuration>
    <system.webServer>  
       <security>  
          <requestFiltering>  
             <requestLimits maxAllowedContentLength="104857600" />  
          </requestFiltering>  
       </security>  
     </system.webServer>  
    

    两者中较小的将优先。对于 IIS,默认为 4MB。

    错误处理

    两者都抛出不同的异常。

    • maxRequestLength - 只要文件超出此设置,您就会收到 Application_Error(标准 ASP 错误)
    • maxAllowedContentLength - 只要文件超出此设置,您就会收到 IIS 错误。

    IIS 错误更难调试,因此建议您将maxAllowedContentLength 设置得更大一些。 maxRequestLength 更容易被捕获,因为它处于应用程序级别。

    来源:

    【讨论】:

      猜你喜欢
      • 2020-11-13
      • 1970-01-01
      • 2019-11-18
      • 1970-01-01
      • 1970-01-01
      • 2015-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多