Table of Contents

Struct UaRuleMode

Namespace
Cloudflare.NET.Security.Firewall.Models
Assembly
Cloudflare.NET.dll

Represents the action to take for a User-Agent blocking rule.

User-Agent blocking modes define what happens when a request's User-Agent header matches the rule's configured pattern.

[JsonConverter(typeof(ExtensibleEnumConverter<UaRuleMode>))]
public readonly struct UaRuleMode : IExtensibleEnum<UaRuleMode>, IEquatable<UaRuleMode>
Implements
Inherited Members

Examples

// Using a known mode with IntelliSense
var mode = UaRuleMode.Block;

// Creating a rule with a specific mode
var rule = new CreateUaRuleRequest(UaRuleMode.ManagedChallenge, config);

// Using implicit conversion from string
UaRuleMode customMode = "new-mode";

Remarks

This is an extensible enum that provides IntelliSense for known values while allowing custom values for new modes that may be added to the Cloudflare API in the future.

Use the static properties for known modes (e.g., Block, Challenge) or create custom values using the constructor or implicit string conversion.

Constructors

UaRuleMode(string)

Creates a new UaRuleMode with the specified value.

public UaRuleMode(string value)

Parameters

value string

The string value representing the mode.

Exceptions

ArgumentNullException

Thrown when value is null.

Properties

Block

Block action - prevents access from matching User-Agents.

public static UaRuleMode Block { get; }

Property Value

UaRuleMode

Remarks

Prevents a visitor from visiting your site. Returns a 403 Forbidden status code.

Challenge

Interactive Challenge action - presents a challenge page to the visitor.

public static UaRuleMode Challenge { get; }

Property Value

UaRuleMode

Remarks

Requires the visitor to complete an interactive challenge before visiting your site. Prevents bots from accessing the site.

JsChallenge

JavaScript Challenge action - presents an Under Attack mode interstitial page.

public static UaRuleMode JsChallenge { get; }

Property Value

UaRuleMode

Remarks

The visitor or client must support JavaScript. The challenge is automatically satisfied by browsers but blocks most bots.

ManagedChallenge

Managed Challenge action - dynamically chooses the appropriate challenge type.

public static UaRuleMode ManagedChallenge { get; }

Property Value

UaRuleMode

Remarks

Cloudflare will dynamically choose the appropriate type of challenge based on the characteristics of a request.

Value

Gets the underlying string value of this mode.

public string Value { get; }

Property Value

string

Methods

Create(string)

Creates a new instance of the extensible enum from the specified string value.

public static UaRuleMode Create(string value)

Parameters

value string

The string value to wrap.

Returns

UaRuleMode

A new instance of UaRuleMode containing the specified value.

Equals(UaRuleMode)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(UaRuleMode other)

Parameters

other UaRuleMode

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

Operators

operator ==(UaRuleMode, UaRuleMode)

Determines whether two UaRuleMode values are equal.

public static bool operator ==(UaRuleMode left, UaRuleMode right)

Parameters

left UaRuleMode
right UaRuleMode

Returns

bool

implicit operator string(UaRuleMode)

Implicitly converts a UaRuleMode to its string value.

public static implicit operator string(UaRuleMode mode)

Parameters

mode UaRuleMode

The mode to convert.

Returns

string

implicit operator UaRuleMode(string)

Implicitly converts a string to a UaRuleMode.

public static implicit operator UaRuleMode(string value)

Parameters

value string

The string value to convert.

Returns

UaRuleMode

operator !=(UaRuleMode, UaRuleMode)

Determines whether two UaRuleMode values are not equal.

public static bool operator !=(UaRuleMode left, UaRuleMode right)

Parameters

left UaRuleMode
right UaRuleMode

Returns

bool

See Also