Table of Contents

Class FilterCollectionExtensions

Namespace
Cuemon.Extensions.AspNetCore.Mvc.Filters
Assembly
Cuemon.Extensions.AspNetCore.Mvc.dll

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.

using Cuemon.Extensions.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;

namespace MyAspNetCoreApp
{
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers(options =>
            {
                // Add HTTP cacheable filter for response caching
                options.Filters.AddHttpCacheable();

                // Add developer-friendly fault descriptor
                options.Filters.AddFaultDescriptor();

                // Add server timing header for performance profiling
                options.Filters.AddServerTiming();

                // Add User-Agent sentinel filter
                options.Filters.AddUserAgentSentinel();

                // Add API throttling sentinel
                options.Filters.AddThrottlingSentinel();

                // Add API key sentinel
                options.Filters.AddApiKeySentinel();
            });

}}
}

Methods

AddApiKeySentinel(FilterCollection)

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

public static IFilterMetadata AddApiKeySentinel(this FilterCollection filters)

Parameters

filters FilterCollection

The FilterCollection to extend.

Returns

IFilterMetadata

A IFilterMetadata representing the added type.

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.

public static IFilterMetadata AddFaultDescriptor(this FilterCollection filters)

Parameters

filters FilterCollection

The FilterCollection to extend.

Returns

IFilterMetadata

A IFilterMetadata representing the added type.

AddHttpCacheable(FilterCollection)

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

public static IFilterMetadata AddHttpCacheable(this FilterCollection filters)

Parameters

filters FilterCollection

The FilterCollection to extend.

Returns

IFilterMetadata

A IFilterMetadata representing the added type.

AddServerTiming(FilterCollection)

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

public static IFilterMetadata AddServerTiming(this FilterCollection filters)

Parameters

filters FilterCollection

The FilterCollection to extend.

Returns

IFilterMetadata

A IFilterMetadata representing the added type.

AddThrottlingSentinel(FilterCollection)

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

public static IFilterMetadata AddThrottlingSentinel(this FilterCollection filters)

Parameters

filters FilterCollection

The FilterCollection to extend.

Returns

IFilterMetadata

A IFilterMetadata representing the added type.

AddUserAgentSentinel(FilterCollection)

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

public static IFilterMetadata AddUserAgentSentinel(this FilterCollection filters)

Parameters

filters FilterCollection

The FilterCollection to extend.

Returns

IFilterMetadata

A IFilterMetadata representing the added type.