• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
PowerCoder
博客园    首页    新随笔    联系   管理    订阅  订阅

asp.net mvc Post上传文件大小限制 (转载)

最近发现在项目中使用jQuery.form插件上传比较大的文件时,上传不了,于是改了下web.config的上传文件最大限制。

<configuration>  
    <system.web>  
        <httpRuntime maxRequestLength="102400" executionTimeout="200" enable="true" />
    </system.web>  
</configuration>

改完后还是不能上传,最后在stackoverflow找到了答案,原来还要配置服务端的最大文件限制。

譬如限制最大文件为100M

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

 

you are hosted in IIS, you need two settings:

  • maxRequestLength - for ASP.net (measured in KB)
  • maxAllowedContentLength - for IIS (measured in Bytes)

 

Error handling

Both throws different exceptions.

  • 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.

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.

 

stackoverflow答案地址:http://stackoverflow.com/questions/23327338/maxrequestlength-for-net-4-5-1-framework

 

posted @ 2018-07-12 16:17  PowerCoder  阅读(3743)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3