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

查看:33
本文介绍了增加 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屋!

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