首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >maxRequestLength for .Net 4.5.1框架

maxRequestLength for .Net 4.5.1框架
EN

Stack Overflow用户
提问于 2014-04-27 18:34:53
回答 1查看 23K关注 0票数 16

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

代码语言:javascript
复制
<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>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-28 02:56:47

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

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

样例配置:(这是100 is的上传限制)

代码语言:javascript
复制
<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处于应用程序级别,因此它更容易捕获。

来源:

票数 22
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23327338

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档