Class UserAgentSentinelFilter
- Namespace
- Cuemon.AspNetCore.Mvc.Filters.Headers
- Assembly
- Cuemon.AspNetCore.Mvc.dll
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
UserAgentSentinelFilter(IOptions<UserAgentSentinelOptions>)
Initializes a new instance of the UserAgentSentinelFilter class.
public UserAgentSentinelFilter(IOptions<UserAgentSentinelOptions> setup)
Parameters
setupIOptions<UserAgentSentinelOptions>The UserAgentSentinelOptions which need to be configured.
Methods
OnActionExecutionAsync(ActionExecutingContext, ActionExecutionDelegate)
Called asynchronously before the action, after model binding is complete.
public override Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
Parameters
contextActionExecutingContextnextActionExecutionDelegateThe ActionExecutionDelegate. Invoked to execute the next action filter or the action itself.