Struct RulesetAction
- Namespace
- Cloudflare.NET.Security.Rulesets.Models
- Assembly
- Cloudflare.NET.dll
Represents an action that can be performed by a rule in the Cloudflare Ruleset Engine.
Actions define what happens when a rule's expression matches an incoming request. Different actions are available depending on the ruleset phase being configured.
[JsonConverter(typeof(ExtensibleEnumConverter<RulesetAction>))]
public readonly struct RulesetAction : IExtensibleEnum<RulesetAction>, IEquatable<RulesetAction>
- Implements
- Inherited Members
Examples
// Using a known action with IntelliSense
var action = RulesetAction.Block;
// Using implicit conversion from string
RulesetAction customAction = "new-action";
// Comparison
if (rule.Action == RulesetAction.ManagedChallenge) { ... }
Remarks
This is an extensible enum that provides IntelliSense for known values while allowing custom values for new actions that may be added to the Cloudflare API in the future.
Use the static properties for known actions (e.g., Block, Challenge) or create custom values using the constructor or implicit string conversion.
Constructors
RulesetAction(string)
Creates a new RulesetAction with the specified value.
public RulesetAction(string value)
Parameters
valuestringThe string value representing the action.
Exceptions
- ArgumentNullException
Thrown when
valueis null.
Properties
Block
Block action - denies matching requests.
public static RulesetAction Block { get; }
Property Value
Remarks
Returns a 403 Forbidden status code to the client. For rate limiting rules, returns a 429 Too Many Requests status code.
Challenge
Interactive Challenge action - presents a challenge page to the visitor.
public static RulesetAction Challenge { get; }
Property Value
Remarks
Requires the visitor to complete an interactive challenge before proceeding. Useful for ensuring that the visitor accessing the site is human.
CompressResponse
Compress Response action - defines compression settings for responses.
public static RulesetAction CompressResponse { get; }
Property Value
Remarks
Configures compression algorithms and settings for the HTTP response. Used in Compression Rules.
Execute
Execute action - executes a specified managed or custom ruleset.
public static RulesetAction Execute { get; }
Property Value
Remarks
Used to deploy rulesets by adding a rule with this action to a phase entry point. Requires action parameters specifying the ruleset ID to execute.
JsChallenge
JavaScript Challenge action - presents an Under Attack mode interstitial page.
public static RulesetAction 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.
Log
Log action - records matching requests without taking any other action.
public static RulesetAction Log { get; }
Property Value
Remarks
Only records the request in logs. Useful for testing rules before enforcing them. Available to Enterprise customers only.
LogCustomField
Log Custom Field action - configures Logpush custom fields.
public static RulesetAction LogCustomField { get; }
Property Value
Remarks
Adds custom fields to Logpush output for matching requests. Available to Enterprise customers with Logpush enabled.
ManagedChallenge
Managed Challenge action - dynamically chooses the appropriate challenge type.
public static RulesetAction ManagedChallenge { get; }
Property Value
Remarks
Cloudflare will choose between a non-interactive challenge, managed challenge, or interactive challenge based on the characteristics of the request. This helps reduce the time humans spend solving CAPTCHAs while maintaining security.
Redirect
Redirect action - navigates the user from a source URL to a target URL.
public static RulesetAction Redirect { get; }
Property Value
Remarks
Returns an HTTP redirect response (301 or 302) to the client. Requires action parameters specifying the redirect target.
Rewrite
Rewrite action - modifies the URI path, query string, or HTTP headers.
public static RulesetAction Rewrite { get; }
Property Value
Remarks
Rewrites various parts of the request before it continues processing. Used in Transform Rules.
Route
Route action - adjusts Host header, SNI, hostname, and destination port.
public static RulesetAction Route { get; }
Property Value
Remarks
Used in Origin Rules to modify how requests are routed to origin servers.
ServeError
Serve Error action - delivers custom error content to the client.
public static RulesetAction ServeError { get; }
Property Value
Remarks
Returns a custom error page with the specified content and status code. Available in specific phases and plans.
SetCacheSettings
Set Cache Settings action - customizes cache behavior.
public static RulesetAction SetCacheSettings { get; }
Property Value
Remarks
Configures caching behavior including TTL, bypass conditions, and cache keys. Used in Cache Rules.
SetConfig
Set Configuration action - changes Cloudflare product settings.
public static RulesetAction SetConfig { get; }
Property Value
Remarks
Modifies the configuration of various Cloudflare features for matching requests. Used in Configuration Rules.
Skip
Skip action - allows users to dynamically skip security features or products.
public static RulesetAction Skip { get; }
Property Value
Remarks
Can skip specific products, rulesets, or rules. Requires action parameters specifying what to skip.
Value
Gets the underlying string value of this action.
public string Value { get; }
Property Value
Methods
Create(string)
Creates a new instance of the extensible enum from the specified string value.
public static RulesetAction Create(string value)
Parameters
valuestringThe string value to wrap.
Returns
- RulesetAction
A new instance of RulesetAction containing the specified value.
Equals(RulesetAction)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(RulesetAction other)
Parameters
otherRulesetActionAn 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 ==(RulesetAction, RulesetAction)
Determines whether two RulesetAction values are equal.
public static bool operator ==(RulesetAction left, RulesetAction right)
Parameters
leftRulesetActionrightRulesetAction
Returns
implicit operator string(RulesetAction)
Implicitly converts a RulesetAction to its string value.
public static implicit operator string(RulesetAction action)
Parameters
actionRulesetActionThe action to convert.
Returns
implicit operator RulesetAction(string)
Implicitly converts a string to a RulesetAction.
public static implicit operator RulesetAction(string value)
Parameters
valuestringThe string value to convert.
Returns
operator !=(RulesetAction, RulesetAction)
Determines whether two RulesetAction values are not equal.
public static bool operator !=(RulesetAction left, RulesetAction right)
Parameters
leftRulesetActionrightRulesetAction