Table of Contents

UserAgentSentinelFilter Class

Definition

A filter that provides an User-Agent sentinel on action methods.

public class UserAgentSentinelFilter : ConfigurableAsyncActionFilter<UserAgentSentinelOptions>, IConfigurable<UserAgentSentinelOptions>, IAsyncActionFilter, IFilterMetadata
Inheritance
UserAgentSentinelFilter
Implements
Inherited Members

Examples

The following example configures to require a known User-Agent header and then creates the filter directly from those options.

using System;
using Cuemon.AspNetCore.Http.Headers;
using Cuemon.AspNetCore.Mvc.Filters.Headers;
using Microsoft.Extensions.Options;

namespace MyApp.Examples;

public static class UserAgentSentinelFilterExample
{
    public static void Demonstrate()
    {
        var options = Options.Create(new UserAgentSentinelOptions
        {
            RequireUserAgentHeader = true,
            ValidateUserAgentHeader = true
        });
        options.Value.AllowedUserAgents.Add("Cuemon-Agent");

        var filter = new UserAgentSentinelFilter(options);

        Console.WriteLine(filter.Options.RequireUserAgentHeader);
        Console.WriteLine(filter.Options.AllowedUserAgents.Count);
    }
}

Constructors

Name Description
UserAgentSentinelFilter(IOptions<UserAgentSentinelOptions>)

Initializes a new instance of the UserAgentSentinelFilter class.

Methods

Name Description
OnActionExecutionAsync(ActionExecutingContext, ActionExecutionDelegate)

Called asynchronously before the action, after model binding is complete.

See Also