Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

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

How can you do the equivalent while running the new ASP.NET Core Kestrel web server?

I get the exception "Request body too large."

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
712 views
Welcome To Ask or Share your Answers For Others

1 Answer

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!

To summarize:

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.

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;
  }

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...