Asp.net web api 如何增加.net core中的请求限制?
我正在尝试上载一些大于.net核心web api中~30Mb限制的文件。我试着遵循我找到的所有建议,都列在下面。无论我尝试了什么,我都会返回404.13错误“请求超出了请求内容长度”。我在Windows10上的VisualStudio中运行,有人知道我如何使它工作吗?我猜在IIS上托管时情况可能会有所不同,但我正试图首先在我的机器上实现这一点Asp.net web api 如何增加.net core中的请求限制?,asp.net-web-api,asp.net-core,visual-studio-2017,Asp.net Web Api,Asp.net Core,Visual Studio 2017,我正在尝试上载一些大于.net核心web api中~30Mb限制的文件。我试着遵循我找到的所有建议,都列在下面。无论我尝试了什么,我都会返回404.13错误“请求超出了请求内容长度”。我在Windows10上的VisualStudio中运行,有人知道我如何使它工作吗?我猜在IIS上托管时情况可能会有所不同,但我正试图首先在我的机器上实现这一点 public static IWebHost BuildWebHost(string[] args) => WebHost.Crea
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseKestrel(o => o.Limits.MaxRequestBodySize = null)
.UseStartup<Startup>()
.Build();
公共静态IWebHost BuildWebHost(字符串[]args)=>
WebHost.CreateDefaultBuilder(args)
.UseKestrel(o=>o.Limits.MaxRequestBodySize=null)
.UseStartup()
.Build();
当尝试获取IHttpMaxRequestBodySizeFeature时,下面这个函数返回null
appBuilder.ServerFeatures.Get<IHttpMaxRequestBodySizeFeature>.MaxRequestBodySize = null;
appBuilder.ServerFeatures.Get.MaxRequestBodySize=null;
将其添加到我的app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<gcServer enabled="true"/>
</runtime>
<system.web>
<httpRuntime maxRequestLength="2147483647"/>
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647"/>
</requestFiltering>
</security>
</system.webServer>
</configuration>
向我的控制器添加属性:
[HttpPost]
[DisableRequestSizeLimit]
//[RequestSizeLimit(100_000_000)]
public IActionResult Document(IList<IFormFile> files)
[HttpPost]
[DisableRequestSizeLimit]
//[RequestSizeLimit(100_000_000)]
公共IActionResult文档(IList文件)
为了回答我自己的问题,原来我应该创建一个Web.config文件,并将我放在app.config文件中的内容放入其中