Table of Contents

FilterCollectionExtensions Class

Definition

Extension methods for the FilterCollection class.

public static class FilterCollectionExtensions
Inheritance
object
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

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.