В настоящее время я м ограничение только по IP:
Код: Выделить всё
services.AddRateLimiter(options =>
{
options.AddPolicy("Api", httpContext =>
RateLimitPartition.GetSlidingWindowLimiter(httpContext.Connection.RemoteIpAddress,
_ => new SlidingWindowRateLimiterOptions
{
AutoReplenishment = true,
PermitLimit = 100,
QueueLimit = 0,
Window = TimeSpan.FromMinutes(1),
SegmentsPerWindow = 20
}));
options.OnRejected = async (context, token) =>
{
context.HttpContext.Response.StatusCode = 429;
await context.HttpContext.Response.WriteAsync(
"Too many requests. Please try again in a few moments. " +
"Read more about our rate limits at https://.",
cancellationToken: token);
};
});
Код: Выделить всё
PartitionedRateLimiter.CreateChained(
PartitionedRateLimiter.Create(httpContext =>
RateLimitPartition.GetSlidingWindowLimiter(httpContext.Connection.RemoteIpAddress.ToString(),
_ => new SlidingWindowRateLimiterOptions
{
AutoReplenishment = true,
PermitLimit = 100,
QueueLimit = 0,
Window = TimeSpan.FromMinutes(1),
SegmentsPerWindow = 20
})),
PartitionedRateLimiter.Create(httpContext =>
RateLimitPartition.GetSlidingWindowLimiter(NO PARTITION KEY HERE,
_ => new SlidingWindowRateLimiterOptions
{
AutoReplenishment = true,
PermitLimit = 1000,
QueueLimit = 0,
Window = TimeSpan.FromMinutes(1),
SegmentsPerWindow = 20
})));
Есть предложения?
Подробнее здесь: https://stackoverflow.com/questions/760 ... e-endpoint
Мобильная версия