【NetCore-技能点】如何配置上传文件大小限制 2021年03月30日 netcore 上传限制 > 超过上传文件大小限制提示的错误 .Net Core 413错误和Request body too large ## Startup.cs ```csharp public void ConfigureServices(IServiceCollection services) { services.AddFxServices(); services.AddAutoMapper(); //解决文件上传Request body too large services.Configure<FormOptions>(x => { x.MultipartBodyLengthLimit = 209_715_200;//最大200M }); } ``` ## Windows IIS配置 1、通过IIS修改 在IIS管理器中,选中网站目录,打开配置编辑器。找到下面的目录。将maxAllowedContentLength修改一下。默认是30000000,不到30M。这边修改成了200M。  2、通过Web.config 配置文件 ```xml <?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> .... <security> <requestFiltering> <requestLimits maxAllowedContentLength="209715200" /> </requestFiltering> </security> </system.webServer> </configuration> ``` ## Linux系统部署 需要在Program.cs 添加如下代码 ```csharp public static IWebHost BuildWebhost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseKestrel(options => { options.Limits.MaxRequestBodySize = 209715200; // 200M }).Build(); ``` ## 参考 [IIS .Net Core 413错误和Request body too large解决办法 - leoxuan - 博客园](https://www.cnblogs.com/leoxuan/p/14115505.html)