.NET Core - Properly stopping Kestrel
Solution 1:
You could use nginx as revrese proxy server. It is a suggested strategy for .NET Core hosting. https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.1
Solution 2:
Isn't correct. Leaving it here for others to not go this route. Read @David's comment below.
You'll have to try this yourself. and it's very risky. You might lock yourself out.
.UseKestrel(options => { options.Limits.MaxConcurrentConnections = 0; })
If you can configure KestrelServerLimits
MaxConcurrentConnections
to 0 you should be able to stop all the traffic.I don't know how you can configure these limits at runtime. But it'll be fun to see an implementation of this.