我们必须转换标签,其中“decryptionKey”和“validationKey”对于我们的开发和测试环境将是不同的。
我们尝试为validationKey和decryptionKey提供不同的变量,但与xdt:Transform和xdt:Locator属性混淆,因为它们将在同一个标记中出现一次。
假设以下是web.config machineKey标记,
<machineKey decryptionKey="012345678910111213141516"
validation="SHA1" validationKey="235487512547896321458778996325456965542126364586965" />
我们必须进行如下的改造,
<machineKey decryptionKey="#{DecryptionKey}#"
validation="SHA1"
validationKey="#{ValidationKey}#"
xdt:Transform="SetAttributes"
xdt:Locator="Match(decryptionKey)"
xdt:Transform="SetAttributes"
xdt:Locator="Match(validationKey)" />
需要这种解决方案,我们必须在单个标签中提供多个变量。
要设置多个属性,需要将它们作为逗号分隔列表传递给SetAttributes。
这是记录here
但是,如果您实际上正在替换所有属性,那么使用xdt:Transform="Replace"
并在每个配置中设置整个标记值可能更容易/更清晰。