jeudi 27 février 2020

How to restrict the number of concurrent requests to a specific ASP.NET Core web method?

I'd like to know the best way to restrict the number of concurrent requests to a specific ASP.NET Core web method? The limit would apply to all users of the application, not just the requesting user.

Calls to my controller method can be memory intensive, so I'd like to restrict the number of requests to, say, 2. I'd like the maximum number of requests to be configurable via app settings.

If 2 requests are already being processed, I like the web method to return an error HTTP response - perhaps 503 for Service Unavailable (unless there is a more appropriate HTTP code?)

  • Is there anything built into .NET Core that I can use? (I'm using .NET Core 3.1)
  • Or should I use a semaphore on the web method?

Thanks

Should I just put a semaphore on the web method?




Aucun commentaire:

Enregistrer un commentaire