适用于.Net 4.5.1框架的maxRequestLength [英] maxRequestLength for .Net 4.5.1 framework

查看:112
本文介绍了适用于.Net 4.5.1框架的maxRequestLength的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to convert a .Net framework 4.0 code into .Net framework 4.5. This is basically a file upload related code. Now I face some problems. What is the maximum value of maxRequestLength? I already add this line in my web.config file but it does not work and the Error code is 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>

推荐答案

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

If you are hosted in IIS, you need two settings:

  • maxRequestLength -用于ASP.net(以KB为单位)
  • maxAllowedContentLength -用于IIS(以字节为单位)
  • maxRequestLength - for ASP.net (measured in KB)
  • maxAllowedContentLength - for IIS (measured in Bytes)

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

Sample config: (this is for 100MB upload limit)

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

两者中的较小者为准.对于IIS,默认值为4MB.

The smaller of the two will take precedence. For IIS, the default is 4MB.

错误处理

两者都会引发不同的异常.

Both throws different exceptions.

  • maxRequestLength -每当文件超过此设置时,您都会收到Application_Error(标准ASP错误)
  • maxAllowedContentLength -每当文件超过此设置时,您都会收到IIS错误.
  • maxRequestLength - Whenever a file exceeds this setting, you'll get an Application_Error (standard ASP error)
  • maxAllowedContentLength - Whenever a file exceeds this setting, you'll get IIS error.

IIS错误更难调试,因此建议将 maxAllowedContentLength 设置为更大. maxRequestLength 较容易捕获,因为它在应用程序级别.

The IIS error is harder to debug, so it is advisable that you set the maxAllowedContentLength larger. maxRequestLength is easier to catch since its at application level.

来源:

这篇关于适用于.Net 4.5.1框架的maxRequestLength的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆