简体   繁体   中英

Replacing machinekey values using web.config transforms

In my web.config file I have the following entry:

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

I need to swap the validationKey and decryptionKey values under certain web publish profiles using the web config transform method. I'm struggling however, as I can't find any examples that achieve more than a basic connection string swap, or suchlike.

Is it possible to actually modify this part of the file using config transforms?

My attempt so far doesn't get recognised when I preview the transform...

<?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>

You can use something like this:

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

Note that I replaced the xdt:Transform to "SetAttributes" not "Replace".

For more reference you can check msdn page .

You can also test the transform here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM