About the current limit of the article, the blog Park is still quite a lot of. This paper makes an example based on filter current limit, which is a concrete example of using Webapithrottle.
Implementation method:
1. Use NuGet to add webapithrottle references to the WEBAPI project
2, to register, generally in the Webapiconfig register method to add, the code is as follows:
1Config. Filters.add (NewCustomthrottlingfilter ()2 {3Policy =NewThrottlepolicy ()4 {5 //IP Configuration Area6Ipthrottling =true,7Clientthrottling =true,8 9 //The endpoint throttling policy configuration is obtained from the enablethrottling attribute. TenEndpointthrottling =true One } A});
Where Customthrottlingfilter is the throttlingfilter that you rewrite, you can also use the default configuration directly. My custom Customthrottlingfilter is as follows:
1 Public classCustomthrottlingfilter:throttlingfilter2 {3 /// <summary>4 ///sets the indentity.5 /// </summary>6 /// <param name= "Request" >The request.</param>7 /// <returns>requestidentity.</returns>8 protected Overriderequestidentity setindentity (httprequestmessage request)9 {Ten varSessionId =string. Empty; One Try A { - varRequestcookie =request. Headers.getcookies (). FirstOrDefault (); - if(Requestcookie! =NULL) the { - foreach(varIteminchRequestCookie.Cookies.Where (item = Item). Name = ="session_id")) - { -SessionId =item. Value; + Break; - } + } A } at Catch(Exception) - { -SessionId =string. Empty; - } - return Newrequestidentity () - { inClientkey =string. Isnullorwhitespace (sessionId)? SessionId:"Anon", -ClientIP =Base. Getclientip (Request). ToString (), toEndpoint =request. RequestUri.AbsolutePath.ToLowerInvariant () + }; - } the}
3, the need to control the interface or controller with a head mark
)] // Control access frequency up to 12 times per minute
No need to control the frequency of access can not add or add
[Disablethrotting]
This enables the use of filters to control the frequency of access to specific APIs, more use of the method can refer to the following address.
Resources:
Webapithrottle Flow-Limiting framework user manual http://www.cnblogs.com/mushroom/p/4659200.html
Control the frequency and current limit of ASP. http://www.cnblogs.com/Irving/p/4664786.html
control ASP. NET Web API call frequency http://www.cnblogs.com/shanyou/p/3194802.html
Implementation of WEBAPI interface Access frequency control