Struct AccessRuleMode
- Namespace
- Cloudflare.NET.Security.Firewall.Models
- Assembly
- Cloudflare.NET.dll
Represents the action to take for an IP Access Rule.
Access rule modes define the behavior when a request matches the rule's configuration. Options range from blocking to allowing, with various challenge types in between.
[JsonConverter(typeof(ExtensibleEnumConverter<AccessRuleMode>))]
public readonly struct AccessRuleMode : IExtensibleEnum<AccessRuleMode>, IEquatable<AccessRuleMode>
- Implements
- Inherited Members
Examples
// Using a known mode with IntelliSense
var mode = AccessRuleMode.Block;
// Using implicit conversion from string
AccessRuleMode customMode = "new-mode";
// Comparison
if (rule.Mode == AccessRuleMode.Whitelist) { ... }
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
AccessRuleMode(string)
Creates a new AccessRuleMode with the specified value.
public AccessRuleMode(string value)
Parameters
valuestringThe string value representing the mode.
Exceptions
- ArgumentNullException
Thrown when
valueis null.
Properties
Block
Block action - denies access to matching requests.
public static AccessRuleMode 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 AccessRuleMode 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 AccessRuleMode JsChallenge { get; }
Property Value
Remarks
The visitor or client must support JavaScript. The challenge is automatically satisfied by browsers but blocks most bots. Useful for blocking DDoS attacks with minimal impact to legitimate visitors.
ManagedChallenge
Managed Challenge action - dynamically chooses the appropriate challenge type.
public static AccessRuleMode ManagedChallenge { get; }
Property Value
Remarks
Cloudflare will dynamically choose the appropriate type of challenge based on the characteristics of a request. This helps reduce the time humans spend solving CAPTCHAs while maintaining security.
Value
Gets the underlying string value of this mode.
public string Value { get; }
Property Value
Whitelist
Whitelist (Allow) action - excludes visitors from all security checks.
public static AccessRuleMode Whitelist { get; }
Property Value
Remarks
Excludes visitors from all security checks, including Browser Integrity Check, Under Attack mode, and the WAF. Use this option when a trusted visitor is being blocked by Cloudflare's default security features. The Allow action takes precedence over the Block action.
Methods
Create(string)
Creates a new instance of the extensible enum from the specified string value.
public static AccessRuleMode Create(string value)
Parameters
valuestringThe string value to wrap.
Returns
- AccessRuleMode
A new instance of AccessRuleMode containing the specified value.
Equals(AccessRuleMode)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(AccessRuleMode other)
Parameters
otherAccessRuleModeAn 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 ==(AccessRuleMode, AccessRuleMode)
Determines whether two AccessRuleMode values are equal.
public static bool operator ==(AccessRuleMode left, AccessRuleMode right)
Parameters
leftAccessRuleModerightAccessRuleMode
Returns
implicit operator string(AccessRuleMode)
Implicitly converts an AccessRuleMode to its string value.
public static implicit operator string(AccessRuleMode mode)
Parameters
modeAccessRuleModeThe mode to convert.
Returns
implicit operator AccessRuleMode(string)
Implicitly converts a string to an AccessRuleMode.
public static implicit operator AccessRuleMode(string value)
Parameters
valuestringThe string value to convert.
Returns
operator !=(AccessRuleMode, AccessRuleMode)
Determines whether two AccessRuleMode values are not equal.
public static bool operator !=(AccessRuleMode left, AccessRuleMode right)
Parameters
leftAccessRuleModerightAccessRuleMode