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
valuestringThe string value representing the mode.
Exceptions
- ArgumentNullException
Thrown when
valueis null.
Properties
Block
Block action - prevents access from matching User-Agents.
public static UaRuleMode Block { get; }
Property Value
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
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
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
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
Methods
Create(string)
Creates a new instance of the extensible enum from the specified string value.
public static UaRuleMode Create(string value)
Parameters
valuestringThe 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
otherUaRuleModeAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand 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
leftUaRuleModerightUaRuleMode
Returns
implicit operator string(UaRuleMode)
Implicitly converts a UaRuleMode to its string value.
public static implicit operator string(UaRuleMode mode)
Parameters
modeUaRuleModeThe mode to convert.
Returns
implicit operator UaRuleMode(string)
Implicitly converts a string to a UaRuleMode.
public static implicit operator UaRuleMode(string value)
Parameters
valuestringThe string value to convert.
Returns
operator !=(UaRuleMode, UaRuleMode)
Determines whether two UaRuleMode values are not equal.
public static bool operator !=(UaRuleMode left, UaRuleMode right)
Parameters
leftUaRuleModerightUaRuleMode