I am trying to configure my .net core API in order to limit the requests.
To achieve this i modify the program.cs class like
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 = 2;
})
//.UseContentRoot(Directory.GetCurrentDirectory())
//.UseIISIntegration()
.UseStartup<Startup>();
});
}
but the problem is when I call my API with a console app using more threads than 2 I get the responses from all threads-calls. The API I have deployed-published it in my local IIS pc.
I consider that I must get only 2 responses and then for the other calls I will get 503 services unavailable.
what is wrong with my code?
EDIT I have read this article How to configure concurrency in .NET Core Web API?, the problem is when I add the web.config
<configuration>
<system.web>
<applicationPool
maxConcurrentRequestsPerCPU="5000"
maxConcurrentThreadsPerCPU="0"
requestQueueLimit="5000" />
</system.web>
</configuration>
i have the warning
the element system. web has invalid child element applicationpool
and i cannot publish the api on iis or run it in iis express