0

I need to generate machineKey in my web application installer and put it into the application's web.config. How can I do this?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
reptile
  • 175
  • 1
  • 9

1 Answers1

2

We need to split the answer in two:

  1. Generate the Machine Key: You will need to implement a custom action to generate the Machine Key (There are many tutorials about creating custom actions so I won't cover that here, review the links below). The important part is the code to generate the Key, review these links: C#, Powershell. You can store the result on an installer property, you may need to make it a secure property to avoid it to apear on the installer logs.

  2. Add the value to the Web.config: Now that you have the key, you can use some of the wix custom actions to modify the web.config, you can use XmlConfig or XmlFile. With this you will be able to modify the Xml file to add the machineKey node using the property created on the previous step. Review the links below for reference on how to use these to update the configuration file.

IMPORTANT: The machineKey element is only valid in the Web.config file at the root of your application and is not valid at the subfolder level.

Additional links:

Adding a Custom Action

Editing Web.Config Connection string settings with Wix

Custom actions with C#

How to pass parameters to the custom action?

Community
  • 1
  • 1
Rolo
  • 3,208
  • 1
  • 24
  • 25