增加 Kestrel 中的上传请求长度限制 [英] Increase upload request length limit in 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 网络服务器时如何做等效的工作?
我收到异常请求正文太大."
推荐答案
我发现了这个有用的公告 确认从 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屋!