我正在尝试通过ARM模板部署APIM策略文件,并出现以下错误:
第24行第6列的元素'set-variable'中的错误:代码块缺少结尾的\\“} \\”字符。确保此块中的所有\\“ {\\”字符都有一个匹配的\\“} \\”字符,并且没有\\“} \\”字符被解释为标记。
我最初是通过Azure门户中的APIM管理刀片创建此策略的,该策略看起来像这样:
<set-variable name="digitalSignature" value="@{
string privateKey = context.Variables.GetValueOrDefault<string>("privateKey", "");
Encoding encoding = System.Text.Encoding.ASCII;
string usablePrivateKey = privateKey.Replace("-", "+").Replace("_", "/");
byte[] privateKeyBytes = Convert.FromBase64String(usablePrivateKey);
byte[] encodedPathAndQueryBytes = encoding.GetBytes(context.Request.Url.Path + context.Request.Url.QueryString);
HMACSHA1 hashAlgorithm = new HMACSHA1(privateKeyBytes);
byte[] hash = hashAlgorithm.ComputeHash(encodedPathAndQueryBytes);
string digitalSignature = Convert.ToBase64String(hash).Replace("+", "-").Replace("/", "_");
return digitalSignature;
}" />
但是,表达式中包含许多无效的XML字符,因此我在* .policy.xml文件中按如下所示转义了上面的代码:
<set-variable name="digitalSignature" value="@{
string privateKey = context.Variables.GetValueOrDefault<string>("privateKey", "");
Encoding encoding = System.Text.Encoding.ASCII;
string usablePrivateKey = privateKey.Replace("-", "+").Replace("_", "/");
byte[] privateKeyBytes = Convert.FromBase64String(usablePrivateKey);
byte[] encodedPathAndQueryBytes = encoding.GetBytes(context.Request.Url.Path + context.Request.Url.QueryString);
HMACSHA1 hashAlgorithm = new HMACSHA1(privateKeyBytes);
byte[] hash = hashAlgorithm.ComputeHash(encodedPathAndQueryBytes);
string digitalSignature = Convert.ToBase64String(hash).Replace("+", "-").Replace("/", "_");
return digitalSignature;
}" />
我想念什么?因为不转义APIM实例的GIT回购中的策略XML文件,我是否甚至需要转义字符?
答案 0 :(得分:1)
在进行更改以使其正常工作的同时,我删除了代码表达式中的所有注释(此问题中未发布),以删除不需要明确且似乎已解决问题的所有内容。
查看注释,由于所有特殊字符均已转义(并已使用几种不同的XML转义实用程序进行了验证),因此我看不到是什么原因引起的,但是由于注释不是必需的,因此我认为此问题已解决。