I am migrating a console app (REST client app) from .NET framework to .NET Core.
In my current (framework) version, I use the app.config file to set the System.Net configuration:
<system.net>
<connectionManagement>
<add address="*" maxconnection="65535"/>
</connectionManagement>
</system.net>
In .NET Core, I have to use a JSON file for configuration. There is no documentation for implementing these settings using the new configuration schema. Does anyone know how this might look inside the new JSON config, or the correct way to implement this in Core? Do I need to build a designated "System.Net.json" config file (separate from an AppSettings.json) specifically to do this?
Thanks.
I assume you're trying to avoid the limit of 2 connections per endpoint, which is default on .NET Framework. Such limit does not exist on .NET Core. So you don't need the above setting at all.
Note that to achieve better perf, we recommend to use HttpClient/HttpClientHandler over HttpWebRequest/ServicePoint on .NET Core. HttpWebRequest/ServicePoint APIs are compat-only.
If you want to limit HttpClient connections, then use HttpClientHandler.MaxConnectionsPerServer
Assuming you are using Kestrel as your web server (and not doing it through IIS implementation), you should be able to set this in your UseKestrel in your BuildWebHost.
It would go something like this:
.UseKestrel(options =>
{
options.Limits.MaxConcurrentConnections = 100;
})
You can also add this in your HttpClientHandler, It's called MaxConnectionsPerServer. It can be seen here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With