简体   繁体   English

如何增加.net core中的请求限制?

[英]How do I increase the request limit in .net core?

I'm trying to upload some files larger than the ~30Mb limit in my .net core web api. 我正在尝试在.net核心网络api中上传一些大于〜30Mb限制的文件。 I've tried following all the advice I've found, all listed below. 我尝试遵循我发现的所有建议,所有建议均在下面列出。 No matter what I've tried I get back a 404.13 error "Request that exceeds the request content length". 无论我尝试了什么,我都会返回404.13错误“请求超出请求内容长度”。 I'm running in visual studio on windows 10, does anybody know how I can get this working? 我正在Windows 10上的Visual Studio中运行,有人知道如何使它正常工作吗? I'm guessing things might be different when hosting on IIS but I'm trying to get this working first on my machine. 我猜想在IIS上托管时情况可能有所不同,但是我想首先在我的计算机上使它工作。

public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseKestrel(o => o.Limits.MaxRequestBodySize = null)
            .UseStartup<Startup>()
            .Build();

This one below returns null when trying to get IHttpMaxRequestBodySizeFeature 尝试获取IHttpMaxRequestBodySizeFeature时,以下内容返回null

appBuilder.ServerFeatures.Get<IHttpMaxRequestBodySizeFeature>.MaxRequestBodySize = null;

Adding it to my app.config: 将其添加到我的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>

Adding attributes to my controller: 向我的控制器添加属性:

[HttpPost]
    [DisableRequestSizeLimit]
    //[RequestSizeLimit(100_000_000)]
    public IActionResult Document(IList<IFormFile> files)

为了回答我自己的问题,事实证明我应该创建一个Web.config文件,并将放入app.config文件中的内容放入其中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM