1、使用nuget,對webapi專案新增webapithrottle的引用
2、進行註冊,一般是在webapiconfig的register方法裡新增,**如下:
config.filters.add(newcustomthrottlingfilter()
});
其中customthrottlingfilter是自己重寫的throttlingfilter,也可以直接用預設配置。我自定義的customthrottlingfilter如下:
publicclass
customthrottlingfilter : throttlingfilter}}
catch
(exception)
return
newrequestidentity();}
}
3、對需要控制的介面或者控制器加上頭標示
[enablethrottling(perminute = 12)]//控制訪問頻率,每分鐘最多12次
不需要控制訪問頻率的可以不加或者加上
[disablethrotting]
**