使用web.config转换替换机器密钥值

Evi*_*lDr 1 asp.net visual-studio one-click-web-publishing visual-studio-2015

在我的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>
Run Code Online (Sandbox Code Playgroud)

我需要使用网络配置转换方法在某些网络发布配置文件下交换validationKeydecryptionKey值。但是,我很挣扎,因为除了基本的连接字符串交换之类的东西,我找不到任何其他例子能达到更多的目的。

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

到目前为止,当我预览转换时,我的尝试尚未得到认可...

<?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>
Run Code Online (Sandbox Code Playgroud)

Mih*_*scu 6

您可以使用如下形式:

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

注意,我xdt:Transform将“ SetAttributes”替换为“ Replace”。

有关更多参考,请检查msdn页面

您也可以在此处测试转换。