EvilDr EvilDr - 1 year ago 220
ASP.NET (C#) Question

Replacing machinekey values using web.config transforms

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

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

I need to swap the
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">
<machineKey validationKey="AE3E7...FAB49" decryptionKey="ADS32....32423twe" xdt:Transform="Replace" xdt:Locator="Match(validationKey)" />

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download