ApplicationBuilderExtensions Class
Definition
- Namespace
- Cuemon.Extensions.AspNetCore.Http.Headers
- Assemblies
- Cuemon.Extensions.AspNetCore.dll
Extension methods for the IApplicationBuilder interface.
public static class ApplicationBuilderExtensions
- Inheritance
-
ApplicationBuilderExtensions
Examples
The following example demonstrates how to add correlation, request, validation, and cache headers to an ASP.NET Core request pipeline.
using System;
using Cuemon.AspNetCore.Http.Headers;
using Cuemon.Extensions.AspNetCore.Http.Headers;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Net.Http.Headers;
namespace DocfxExamples;
public class HeaderPipelineExample
{
public static void Configure(IApplicationBuilder app)
{
app.UseCorrelationIdentifier(options => options.HeaderName = "X-Correlation-ID");
app.UseRequestIdentifier(options => options.HeaderName = "X-Request-ID");
app.UseUserAgentSentinel(options =>
{
options.RequireUserAgentHeader = true;
options.ValidateUserAgentHeader = true;
options.AllowedUserAgents.Add("Cuemon-Agent");
});
app.UseApiKeySentinel(options =>
{
options.HeaderName = "X-Test-Key";
options.AllowedKeys.Add("known-key");
});
app.UseCacheControl(options =>
{
options.CacheControl.MaxAge = TimeSpan.FromHours(1);
options.CacheControl.Public = true;
options.Expires = new ExpiresHeaderValue(TimeSpan.FromHours(1));
});
app.UseVaryAccept();
app.Run(context => context.Response.WriteAsync("ok"));
}
}
Methods
| Name | Description |
|---|---|
| UseApiKeySentinel(IApplicationBuilder, Action<ApiKeySentinelOptions>) | Adds an API key header parser to the IApplicationBuilder request execution pipeline. |
| UseCacheControl(IApplicationBuilder, Action<CacheableOptions>) | Adds an HTTP Cache-Control and HTTP Expires header to the IApplicationBuilder request execution pipeline. |
| UseCorrelationIdentifier(IApplicationBuilder, Action<CorrelationIdentifierOptions>) | Adds a correlation identifier HTTP header to the IApplicationBuilder request execution pipeline. |
| UseRequestIdentifier(IApplicationBuilder, Action<RequestIdentifierOptions>) | Adds a request identifier HTTP header to the IApplicationBuilder request execution pipeline. |
| UseUserAgentSentinel(IApplicationBuilder, Action<UserAgentSentinelOptions>) | Adds a HTTP User-Agent header parser to the IApplicationBuilder request execution pipeline. |
| UseVaryAccept(IApplicationBuilder) | Adds an HTTP Vary: Accept header to the IApplicationBuilder request execution pipeline. |