加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – .Net 4.5.1框架的maxRequestLength

发布时间:2020-12-15 20:54:57 所属栏目:asp.Net 来源:网络整理
导读:我想将.Net framework 4.0代码转换为.Net framework 4.5.这基本上是与文件上传相关的代码.现在我面临一些问题. maxRequestLength的最大值是多少? 我已经在我的web.config文件中添加了这一行,但它不起作用,错误代码是0x800700b7 system.webhttpRuntime maxRe
我想将.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>

解决方法

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

> maxRequestLength – 用于ASP.net(以KB为单位)
> maxAllowedContentLength – 用于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更容易捕获.

资料来源:

> http://forums.iis.net/t/1169846.aspx
> Which gets priority,maxRequestLength or maxAllowedContentLength?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读