增加Kestrel中的上传请求长度限制 [英] Increase upload request length limit in Kestrel

查看:193
本文介绍了增加Kestrel中的上传请求长度限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行ASP.NET Core Web应用程序,并希望上传大文件.

I am running an ASP.NET Core web app and want to upload large files.

我知道在运行IIS时,可以通过web.config更改限制:

I know that when running IIS, the limits can be changed via web.config:

<httpRuntime maxRequestLength="1048576" /> 
...
<requestLimits maxAllowedContentLength="1073741824" /> 

在运行新的ASP.NET Core Kestrel Web服务器时如何做等效的工作?

我收到异常请求正文太大".

推荐答案

我发现此有用的公告确认从ASP.NET Core 2.0开始有28.6 MB的主体大小限制,但更重要的是显示了如何解决它!

I found this helpful announcement that confirms there is a 28.6 MB body size limit starting with ASP.NET Core 2.0, but more importantly shows how to get around it!

总结:

对于单个控制器或操作,请使用 [DisableRequestSizeLimit] 属性没有限制,或者 [RequestSizeLimit(100_000_000)] 指定自定义限制.

For a single controller or action, use the [DisableRequestSizeLimit] attribute to have no limit, or the [RequestSizeLimit(100_000_000)] to specify a custom limit.

要在BuildWebHost()方法内部和Program.cs文件内部进行全局更改,请在下面添加.UseKestrel选项:

To change it globally, inside of the BuildWebHost() method, inside the Program.cs file, add the .UseKestrel option below:

WebHost.CreateDefaultBuilder(args)
  .UseStartup<Startup>()
  .UseKestrel(options =>
  {
    options.Limits.MaxRequestBodySize = null;
  }

为更加清楚起见,您还可以参考 Kestrel选项文档.

For additional clarity, you can also refer to the Kestrel options documentation.

这篇关于增加Kestrel中的上传请求长度限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆