I am migrating a WebApi from .net5 to .net6. It's going fairly well, but have run into the problem of how to configure Kestrel during startup. The following code is from the Main method of the Program.cs file:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddVariousStuff();
builder.Host
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(serverOptions =>
{
serverOptions.Limits.MaxConcurrentConnections = 100;
serverOptions.Limits.MaxConcurrentUpgradedConnections = 100;
serverOptions.Limits.MaxRequestBodySize = 52428800;
});
});
var app = builder.Build();
app.UseStuffEtc();
app.Run();
The app startup crashes with the following exception:
System.NotSupportedException: ConfigureWebHost() is not supported by WebApplicationBuilder.Host. Use the WebApplication returned by WebApplicationBuilder.Build() instead.
If I remove anything related to ConfigureWebHostDefaults, then app starts no problem. Am unable to figure out how roll with the new .net6 Kestrel server startup config.
builder.WebHost.UseSentry();
lol thank you! I was also trying to usebuilder.Host.ConfigureWebHostDefaults(builder => { });
– Wapiti