Class ApplicationBuilderExtensions
- Namespace
- Cuemon.Extensions.AspNetCore.Http.Headers
- 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 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
UseApiKeySentinel(IApplicationBuilder, Action<ApiKeySentinelOptions>)
Adds an API key header parser to the IApplicationBuilder request execution pipeline.
public static IApplicationBuilder UseApiKeySentinel(this IApplicationBuilder builder, Action<ApiKeySentinelOptions> setup = null)
Parameters
builderIApplicationBuilderThe type that provides the mechanisms to configure an application’s request pipeline.
setupAction<ApiKeySentinelOptions>The ApiKeySentinelOptions middleware which may be configured.
Returns
- IApplicationBuilder
An IApplicationBuilder that can be used to further configure the request pipeline.
UseCacheControl(IApplicationBuilder, Action<CacheableOptions>)
Adds an HTTP Cache-Control and HTTP Expires header to the IApplicationBuilder request execution pipeline.
public static IApplicationBuilder UseCacheControl(this IApplicationBuilder builder, Action<CacheableOptions> setup = null)
Parameters
builderIApplicationBuilderThe type that provides the mechanisms to configure an application’s request pipeline.
setupAction<CacheableOptions>The CacheableOptions middleware which may be configured.
Returns
- IApplicationBuilder
An IApplicationBuilder that can be used to further configure the request pipeline.
UseCorrelationIdentifier(IApplicationBuilder, Action<CorrelationIdentifierOptions>)
Adds a correlation identifier HTTP header to the IApplicationBuilder request execution pipeline.
public static IApplicationBuilder UseCorrelationIdentifier(this IApplicationBuilder builder, Action<CorrelationIdentifierOptions> setup = null)
Parameters
builderIApplicationBuilderThe type that provides the mechanisms to configure an application’s request pipeline.
setupAction<CorrelationIdentifierOptions>The CorrelationIdentifierOptions middleware which may be configured.
Returns
- IApplicationBuilder
An IApplicationBuilder that can be used to further configure the request pipeline.
Remarks
Default HTTP header name is X-Correlation-ID.
UseRequestIdentifier(IApplicationBuilder, Action<RequestIdentifierOptions>)
Adds a request identifier HTTP header to the IApplicationBuilder request execution pipeline.
public static IApplicationBuilder UseRequestIdentifier(this IApplicationBuilder builder, Action<RequestIdentifierOptions> setup = null)
Parameters
builderIApplicationBuilderThe type that provides the mechanisms to configure an application’s request pipeline.
setupAction<RequestIdentifierOptions>The RequestIdentifierOptions middleware which may be configured.
Returns
- IApplicationBuilder
An IApplicationBuilder that can be used to further configure the request pipeline.
Remarks
Default HTTP header name is X-Request-ID.
UseUserAgentSentinel(IApplicationBuilder, Action<UserAgentSentinelOptions>)
Adds a HTTP User-Agent header parser to the IApplicationBuilder request execution pipeline.
public static IApplicationBuilder UseUserAgentSentinel(this IApplicationBuilder builder, Action<UserAgentSentinelOptions> setup = null)
Parameters
builderIApplicationBuilderThe type that provides the mechanisms to configure an application’s request pipeline.
setupAction<UserAgentSentinelOptions>The UserAgentSentinelOptions middleware which may be configured.
Returns
- IApplicationBuilder
An IApplicationBuilder that can be used to further configure the request pipeline.
UseVaryAccept(IApplicationBuilder)
Adds an HTTP Vary: Accept header to the IApplicationBuilder request execution pipeline.
public static IApplicationBuilder UseVaryAccept(this IApplicationBuilder builder)
Parameters
builderIApplicationBuilderThe type that provides the mechanisms to configure an application's request pipeline.
Returns
- IApplicationBuilder
An IApplicationBuilder that can be used to further configure the request pipeline.