I referred to the following pages.
https://learn.microsoft.com/en-us/aspnet/core/performance/rate-limit?view=aspnetcore-7.0
For example, I want to limit the index.razor page to 10 requests per minute.
I have the following code.
builder.Services.AddRateLimiter(_ => _
.AddFixedWindowLimiter(policyName: "fixed", options =>
{
options.PermitLimit = 10;
options.Window = TimeSpan.FromSeconds(60);
options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
options.QueueLimit = 0;
}));
:
:
app.UseRouting();
app.UseRateLimiter();
I tried writing the code as below but it didn't work.
@page "/counter"
@attribute [EnableRateLimiting("fixed")]
@using Microsoft.AspNetCore.RateLimiting
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role="status">Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
How to resolve it?
Thanks.