Azure APIM策略检查大于或等于



在我的poral中,我有查询参数调用"PageSize";我需要检查用户输入情况更糟,需要向用户显示消息

比在我的出境区我放

<outbound>
<choose>
<when condition="@(context.Request.Url.Query.GetValueOrDefault("PageSize")) > = 20">
<set-status code="205" reason="validation" />
<set-body template="none">{"Message":"PageSize need to be less than 20"}</set-body>
</when>
</choose>
<base />
</outbound>

但当我试图保存门户时,会给我以下错误消息

One or more fields contain incorrect values:
Error in element 'choose' on line 21, column 10: Expression syntax is invalid.

您必须在condition="@()中定义完整条件
这意味着它不必在括号之外:> = 20

请不要在> =之间使用空格
正确:>=

查询的值为string。您必须将该值转换为int

完整的固定出站策略:

<outbound>
<choose>
<when condition="@(int.Parse(context.Request.Url.Query.GetValueOrDefault("PageSize")) >= 20) ">
<set-status code="205" reason="validation" />
<set-body template="none">{"Message":"PageSize need to be less than 20"}</set-body>
</when>
</choose>
<base />
</outbound>

最新更新