Answered by:
How to limit the number of HttpWebRequests from a website

Question
-
User-1664485818 posted
Hi folks, how do you limit the number of HttpWebRequest from a website, would something like this work?
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.net> <connectionManagement> <add address="*" maxconnection="100" /> </connectionManagement> </system.net> </configuration>
Tuesday, July 19, 2016 2:59 PM
Answers
-
User753101303 posted
What you saw is to limit simultaneous connection. Here it looks rather like a quota issue. I would so something such as :
- counting a daily number of connections. It could be exposed as a performance counter or monitor that to see if you are close. Ah the API provider shoudl also have a UI (and maybe a service) that would allow to get this information
- see what happens when the quota is exceeded and try to handle this failure caseThis way you should be able to survive if this API is not available (depending on how important it is) and you have to monitor that to anticipate if your app could reach this limit so that you can act accordingly...
For the counter, it could be made maybe of "slots" so that you you can have the count value for the last 24 hours.. (but see perhaps first on the API provider side).
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, July 20, 2016 10:42 AM
All replies
-
User283571144 posted
Hi brucey,
<connectionManagement> <add address="*" maxconnection="100" /> </connectionManagement>As far as I know, connectionManagement defines the maximum number of connections to a server or group of servers.
For example, if you replace "*" with "www.google.com", it means connectionManagement only applicable to Google access.More details, you could refer to follow link:
https://msdn.microsoft.com/en-us/library/fb6y0fyc.aspx
Besides, we could use ServicePoint class to manage connections to the Internet and to help them achieve optimum scale and performance.
More details, you could refer to follow link:
https://msdn.microsoft.com/en-us/library/7af54za5(v=vs.110).aspx
Best Regards,
Brando
Tuesday, July 19, 2016 4:10 PM -
User753101303 posted
Hi,
It should be for outgoing connections. If instead you want rather to block incoming connections you could perhaps try something such as http://www.iis.net/downloads/microsoft/dynamic-ip-restrictions.
Tuesday, July 19, 2016 4:19 PM -
User-1664485818 posted
Yes its for outgoing connections, I have to limit the amount of HttpWebRequests from our website to a API, I am only only to hit the API 10,000 times per day, any help much appreciated.
Tuesday, July 19, 2016 6:54 PM -
User283571144 posted
Hi brucey,
Yes its for outgoing connections, I have to limit the amount of HttpWebRequests from our website to a API, I am only only to hit the API 10,000 times per day, any help much appreciated.According to your description, I suggest you could store the number of sending requests to API and date into database or sever session.
For example, when we click a button, we should check the number and date from database before sending requests to API.
If this number more than 10,000 in one day, you prevent this event, else we could fire this event and set this number plus one and store into the database.
Best Regards,
Brando
Wednesday, July 20, 2016 9:58 AM -
User753101303 posted
What you saw is to limit simultaneous connection. Here it looks rather like a quota issue. I would so something such as :
- counting a daily number of connections. It could be exposed as a performance counter or monitor that to see if you are close. Ah the API provider shoudl also have a UI (and maybe a service) that would allow to get this information
- see what happens when the quota is exceeded and try to handle this failure caseThis way you should be able to survive if this API is not available (depending on how important it is) and you have to monitor that to anticipate if your app could reach this limit so that you can act accordingly...
For the counter, it could be made maybe of "slots" so that you you can have the count value for the last 24 hours.. (but see perhaps first on the API provider side).
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, July 20, 2016 10:42 AM -
User-1902643333 posted
Yes its for outgoing connections, I have to limit the amount of HttpWebRequests from our website to a API, I am only only to hit the API 10,000 times per day, any help much appreciated.
Just create a "Global.asax", where you can create an "Application" as a global scope to count how many requests there are. If it adds up to 1000, just redirect to a use-defined error page.
Wednesday, July 20, 2016 11:16 AM