【问题标题】:Replacing machinekey values using web.config transforms使用 web.config 转换替换机器键值
【发布时间】:2016-11-18 11:00:40
【问题描述】:

在我的 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>

我需要使用 web config 转换方法交换某些 web 发布配置文件下的 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>

【问题讨论】:

    标签: asp.net visual-studio visual-studio-2015 one-click-web-publishing


    【解决方案1】:

    你可以这样使用:

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

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

    更多参考您可以查看msdn page

    您还可以测试转换here

    【讨论】:

    • 效果很好。谢谢!
    猜你喜欢
    • 2012-02-15
    • 2011-04-07
    • 2018-07-13
    • 1970-01-01
    • 2011-12-02
    • 1970-01-01
    • 2013-04-15
    • 2013-08-13
    • 2012-04-27
    相关资源
    最近更新 更多