Last active
May 5, 2021 20:48
-
-
Save manoj-choudhari-git/3598a6f6c4576d15c4637e6e0be3556d to your computer and use it in GitHub Desktop.
ConfigureKestrel method code to apply the limits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
CreateHostBuilder(args).Build().Run(); | |
} | |
public static IHostBuilder CreateHostBuilder(string[] args) => | |
Host.CreateDefaultBuilder(args) | |
.ConfigureWebHostDefaults(webBuilder => | |
{ | |
webBuilder.ConfigureKestrel(serverOptions => | |
{ | |
serverOptions.Limits.MaxConcurrentConnections = 100; | |
serverOptions.Limits.MaxConcurrentUpgradedConnections = 100; | |
serverOptions.Limits.MaxRequestBodySize = 10 * 1024; | |
serverOptions.Limits.MinRequestBodyDataRate = | |
new MinDataRate(bytesPerSecond: 100, | |
gracePeriod: TimeSpan.FromSeconds(10)); | |
serverOptions.Limits.MinResponseDataRate = | |
new MinDataRate(bytesPerSecond: 100, | |
gracePeriod: TimeSpan.FromSeconds(10)); | |
serverOptions.Listen(IPAddress.Loopback, 5000); | |
serverOptions.Listen(IPAddress.Loopback, 5001, | |
listenOptions => | |
{ | |
listenOptions.UseHttps("testCert.pfx", | |
"testPassword"); | |
}); | |
serverOptions.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2); | |
serverOptions.Limits.RequestHeadersTimeout = TimeSpan.FromMinutes(1); | |
}); | |
webBuilder.UseStartup<Startup>(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment