Controlling the ASP. NET Web API Call frequency

Source: Internet
Author: User

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 (Newthrottlinghandler    , New Inmemorythrottlestore (),      id =     Timespan.fromhours (1))); 
The Ithrottlestore interface uses ID + the 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. 
Throttling ASP. NET Web API calls
Introducing ASP. NET Web API Throttling Handler
Throttling Suite for Web API

Controlling the ASP. NET Web API Call frequency

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.