Table of Contents

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

value string

The string value representing the action.

Exceptions

ArgumentNullException

Thrown when value is null.

Properties

Block

Block action - denies matching requests.

public static RulesetAction Block { get; }

Property Value

RulesetAction

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

RulesetAction

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

RulesetAction

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

RulesetAction

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

RulesetAction

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

RulesetAction

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

RulesetAction

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

RulesetAction

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

RulesetAction

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

RulesetAction

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

RulesetAction

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

RulesetAction

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

RulesetAction

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

RulesetAction

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

RulesetAction

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

string

Methods

Create(string)

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

public static RulesetAction Create(string value)

Parameters

value string

The 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

other RulesetAction

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 ==(RulesetAction, RulesetAction)

Determines whether two RulesetAction values are equal.

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

Parameters

left RulesetAction
right RulesetAction

Returns

bool

implicit operator string(RulesetAction)

Implicitly converts a RulesetAction to its string value.

public static implicit operator string(RulesetAction action)

Parameters

action RulesetAction

The action to convert.

Returns

string

implicit operator RulesetAction(string)

Implicitly converts a string to a RulesetAction.

public static implicit operator RulesetAction(string value)

Parameters

value string

The string value to convert.

Returns

RulesetAction

operator !=(RulesetAction, RulesetAction)

Determines whether two RulesetAction values are not equal.

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

Parameters

left RulesetAction
right RulesetAction

Returns

bool

See Also