Table of Contents

FilterCollectionExtensions Class

Definition

Namespace
Cuemon.Extensions.AspNetCore.Mvc.Filters
Assemblies
Cuemon.Extensions.AspNetCore.Mvc.dll
Source
src/Cuemon.Extensions.AspNetCore.Mvc/Filters/FilterCollectionExtensions.cs

Extension methods for the FilterCollection class.

public static class FilterCollectionExtensions
Inheritance
FilterCollectionExtensions

Examples

The following example demonstrates how to use the FilterCollectionExtensions extension methods to register common ASP.NET Core MVC filters.

// Program.cs
using System;
using Cuemon.Extensions.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

var services = new ServiceCollection();
services.AddLogging();
services.AddControllers(options =>
{
    options.Filters.AddHttpCacheable();
    options.Filters.AddFaultDescriptor();
    options.Filters.AddServerTiming();
    options.Filters.AddUserAgentSentinel();
    options.Filters.AddThrottlingSentinel();
    options.Filters.AddApiKeySentinel();
});

using var provider = services.BuildServiceProvider();
var options = provider.GetRequiredService<IOptions<MvcOptions>>().Value;
Console.WriteLine(options.Filters.Count);

Methods

Name Description
AddApiKeySentinel(FilterCollection)

Adds an ApiKeySentinelFilter to the filters handled in the MVC request pipeline that provides an API key sentinel on action methods.

AddFaultDescriptor(FilterCollection)

Adds a FaultDescriptorFilter to the filters handled in the MVC request pipeline that, after an action has faulted, provides developer friendly information about an Exception along with a correct HttpStatusCode.

AddHttpCacheable(FilterCollection)

Adds a HttpCacheableFilter to the filters handled in the MVC request pipeline that will invoke filters implementing the ICacheableObjectResult interface

AddServerTiming(FilterCollection)

Adds a ServerTimingFilter to the filters handled in the MVC request pipeline that performs time measure profiling of action methods.

AddThrottlingSentinel(FilterCollection)

Adds a ThrottlingSentinelFilter to the filters handled in the MVC request pipeline that provides an API throttling on action methods.

AddUserAgentSentinel(FilterCollection)

Adds an UserAgentSentinelFilter to the filters handled in the MVC request pipeline that provides an User-Agent sentinel on action methods.