Class ApplicationBuilderExtensions
- Namespace
- Cuemon.Extensions.AspNetCore.Http.Throttling
- Assembly
- Cuemon.Extensions.AspNetCore.dll
Extension methods for the IApplicationBuilder interface.
public static class ApplicationBuilderExtensions
- Inheritance
-
ApplicationBuilderExtensions
Examples
The following example demonstrates how to add a request rate limiting middleware to an ASP.NET Core application pipeline.
using System;
using Cuemon;
using Cuemon.AspNetCore.Http.Throttling;
using Cuemon.Extensions.AspNetCore.Http.Throttling;
using Microsoft.AspNetCore.Builder;
namespace Examples;
public class StartupPipeline
{
public void Configure(IApplicationBuilder app)
{
app.UseThrottlingSentinel(o =>
{
o.Quota = new ThrottleQuota(100, 1, TimeUnit.Minutes);
o.ContextResolver = ctx => ctx.Connection.RemoteIpAddress?.ToString() ?? "unknown";
});
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
Methods
UseThrottlingSentinel(IApplicationBuilder, Action<ThrottlingSentinelOptions>)
Adds a HTTP requests rate limiting / throttling guard to the IApplicationBuilder request execution pipeline.
public static IApplicationBuilder UseThrottlingSentinel(this IApplicationBuilder builder, Action<ThrottlingSentinelOptions> setup = null)
Parameters
builderIApplicationBuilderThe type that provides the mechanisms to configure an application’s request pipeline.
setupAction<ThrottlingSentinelOptions>The ThrottlingSentinelOptions middleware which may be configured.
Returns
- IApplicationBuilder
A reference to
builderafter the operation has completed.