Table of Contents

UserAgentSentinelOptions Class

Definition

Configuration options for UserAgentSentinelMiddleware and related.

public class UserAgentSentinelOptions : IValidatableParameterObject, IParameterObject
Inheritance
object
UserAgentSentinelOptions
Implements

Examples

The following example demonstrates how to configure to restrict which User-Agent headers are allowed.

using System;
using System.Collections.Generic;

        namespace Cuemon.AspNetCore.Http.Headers;

        public static class UserAgentSentinelOptionsExample
        {
            public static void Demonstrate()
            {
                var options = new UserAgentSentinelOptions
        {
            RequireUserAgentHeader = true,
            ValidateUserAgentHeader = true,
            AllowedUserAgents = new List<string> { "Cuemon-Agent" }
        };

        options.ValidateOptions();
        using var response = options.ResponseHandler("Unknown-Agent");
        var message = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
        Console.WriteLine(message);
            }
        }

Constructors

Name Description
UserAgentSentinelOptions()

Initializes a new instance of the UserAgentSentinelOptions class.

Properties

Name Description
AllowedUserAgents

Gets or sets a list of whitelisted user agents.

BadRequestMessage

Gets or sets the message of a request missing the requirements of a User-Agent header.

ForbiddenMessage

Gets or sets the message of a request without a valid User-Agent header.

RequireUserAgentHeader

Gets or sets a value indicating whether a HTTP User-Agent header must be present in the request.

ResponseHandler

Gets or sets the function delegate that configures the response in the form of a HttpResponseMessage.

UseGenericResponse

Gets or sets a value indicating whether the produced ResponseHandler should be as neutral as possible.

ValidateUserAgentHeader

Gets or sets a value indicating whether a HTTP User-Agent header must be validated against AllowedUserAgents.

Methods

Name Description
ValidateOptions()

Determines whether the public read-write properties of this instance are in a valid state.