Reference Address: http://www.cnblogs.com/shanyou/p/3194802.html
Installing the NuGet package: Webapicontrib
Many APIs, such as the GitHub ' s API, have traffic control practices. Use rate limiting to prevent the client from making too many requests to your API in a short amount of time. For example, we can limit the anonymous API client to a maximum of 60 requests per hour, and we can make more requests from more authenticated clients. So how does ASP. NET Webapi implement such a function? There is an implementation above the project Webapicontrib: https://github.com/WebApiContrib/WebAPIContrib/blob/master/src/WebApiContrib/ Messagehandlers/throttlinghandler.cs, with good scalability.
The simplest approach is to use Throttlinghandler to register with simple parameters, such as controlling 60 requests per user every hour:
Config. Messagehandlers.add ( new Throttlinghandler,new Inmemorythrottlestore (), timespan.fromhours (1)));
Ithrottlestore interface uses ID + current number of requests. Inmemorythrottlestore has only one in-memory storage, but you can easily extend the implementation as a distributed cache or database. You can also easily customize the behavior of the Throttlinghandler, for example, we have better control over an IP address.
CONFIG. Messagehandlers.add (new Throttlinghandler ( new Inmemorythrottlestore (), ID /span>=> if ( id = = 10.0.0.1 " return 5000 return 60 ; }, Timespan.fromhours ( 1 )));
ASP. NET Web API control Request Frequency