Docs

Store Configuration for Rules

Use C# in Rules

Even though you typically write Rules in JavaScript, there is support for using C# by making use of Edge.js. In order to use C# in your Rule you will first need to require Edge:

You can then declare an Edge function, and embed the C# code inside the function body using a JavaScript multi-line comment block:

Please note from the code above that you need to declare the C# function as an async Lambda taking a single input parameter:

Finally, you can call the helloWorld function from somewhere else inside your Rule. Here is the full sample code for the Rule making use of C#:

You can take this one step further by adding the result of the C# function as a namespaced Claim:

You can also pass the user or context parameters which was passed into the Rule to the C# function. In this case you will need to declare the input parameter of the Lambda function as dynamic so you can access the attributes from the JavaScript object inside the C# function. You will also need to pass the user or context object to the helloWorld function.

In the updated sample below you can see that the C# function replaces the @ and . characters in the user's email address with the _ character:

For details on the properties of the context argument refer to Context Argument Properties in Rules.