Tools, FAQ, Tutorials:
'@(...)' Expressions in Azure API Policy
How to use the "@(...)" expression in Azure API Policy?
✍: FYIcenter.com
The "@(...)" expression in Azure API Policy can be used
to include a single C# expression as the attribute value or text value in most policy statements.
When a "@(...)" expression is included in a policy statement, the C# expression will be evaluated first and the result of the evaluation will be used in the policy statement.
For example, the following "set-variable" policy statement uses a "@(...)" expression as an attribute value to set a new variable to be used later:
<set-variable name="isMobile" value="@(Context.Request.Headers["User-Agent"].Contains("iPhone"))" />
The following "trace" policy statements uses a "@(...)" expression as a text content to verify some properties from the built-in "Context" object:
<trace source="MyDebug">@("I am here!")</trace>
<trace source="MyDebug">@(context.Request.Url.Path)</trace>
<trace source="MyDebug">@(context.Request.MatchedParameters["id"])</trace>
Note that the C# expression inside "@(...)" must be XML friendly. For example, the "<" sign should be replaced with <. But Azure takes the "<" sign too without any trouble:
<trace source="MyDebug">@( 1 < 2 )</trace> <trace source="MyDebug">@( 1 < 2 )</trace>
Also note that the "@(...)" expression can not be mixed with text as attribute values or text contents. The following examples are wrong uses of "@(...)" expressions:
<set-variable name="message" value="Hello @("world!")" />
<trace source="MyDebug">Hello @("world!")</trace>
<trace source="MyDebug">@("Hello") world!</trace>
For more information on "@(...)" expressions, see API Management policy expressions Website.
2018-02-14, ∼4970🔥, 0💬
Popular Posts:
What is the Azure AD v1.0 OpenID Metadata Document? Azure AD v1.0 OpenID Metadata Document is an onl...
Can Multiple Paragraphs Be Included in a List Item? Yes. You can include multiple paragraphs in a si...
Where to find tutorials on Using Azure API Management Publisher Dashboard? Here is a list of tutoria...
How to build a PHP script to dump Azure AD 2.0 Authentication Response? If you are use the Azure-AD-...
How to Install Docker Desktop 2.5.0 on Windows 10? You can follow this tutorial to Install Docker De...