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
分类:
ASP.NET
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架