使用 web.config 转换替换 machinekey 值

Replacing machinekey values using web.config transforms

在我的 web.config 文件中有以下条目:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <machineKey validationKey="656....9CCF" decryptionKey="9020.....659" validation="SHA1" decryption="AES" />
    </system.web>
</configuration>

我需要使用网络配置转换方法交换某些网络发布配置文件下的 validationKeydecryptionKey 值。然而,我正在努力,因为我找不到任何实现超过基本连接字符串交换或类似功能的示例。

是否可以使用配置转换实际修改文件的这一部分?

目前我的尝试在预览转换时没有得到识别...

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <system.web>
        <machineKey validationKey="AE3E7...FAB49" decryptionKey="ADS32....32423twe" xdt:Transform="Replace" xdt:Locator="Match(validationKey)" />
    </system.web>
</configuration>

你可以这样使用:

<machineKey validationKey="AE3E7...FAB49" decryptionKey="ADS32....32423twe" 
         xdt:Transform="SetAttributes" xdt:Locator="XPath(../machineKey)"/>

请注意,我将 xdt:Transform 替换为 "SetAttributes" 而不是 "Replace"。

有关更多参考,您可以查看 msdn page

您还可以测试转换 here