21

I would like to add the machineKey to my machine.config since I am working with programmatic encryption of web.config connection strings in a web farm scenario.

My question is, where do I place the machineKey in the machine.config file? There isn't one already there that I can replace, I suspect it's being autogenerated, so where should it be placed?

Rami Alhamad
  • 281
  • 1
  • 3
  • 9

4 Answers4

28

Just place it under <system.web>

If you need a key generated, use the process as shown in this SO post

NovaDev
  • 2,737
  • 5
  • 29
  • 43
peroija
  • 1,982
  • 4
  • 21
  • 37
  • 2
    Should you not just generate the key from within IIS? – medina Nov 05 '12 at 14:31
  • @davidb I figured I should respond since this is still getting upvotes. Using IIS certainly is an option for those with access to it (I know, devs REALLY should have local IIS set up but I've come across many that don't bother with it) – peroija Feb 17 '17 at 18:12
  • @davidb IIS Express (the one that comes with VS) and an azure shared webapp is generally sufficient when the production application is going to be on Azure. So +1 for that link! – galdin Mar 06 '17 at 12:00
  • 1
    here is another site to generate the key https://www.allkeysgenerator.com/Random/ASP-Net-MachineKey-Generator.aspx – Marisol Gutiérrez Jun 19 '19 at 13:07
  • http://aspnetresources.com/tools/machineKey not exists anymore. (and that's a Japanese site?) – The Anh Nguyen Nov 11 '19 at 07:15
10

Inside <system.web>:

<system.web>
    <machineKey 
        validationKey="....." 
        decryptionKey="....." 
    />

which is at the bottom of the file in mine at least. I don't think the order of elements in system.web matters, as long as it's the top level directly beneath the system.web element.

Rup
  • 33,765
  • 9
  • 83
  • 112
2

Get keys from sites can be a risk of security.

there's a simple way to do it, just use your IIS console

type inetMgr in Start

The IIS Console open. Click in Computer Keys

Computer Keys

The next step is set your keys. Select the appropriate, unflag the boxes to generate manually your keys, and finally click Generate Keys.

Screen where generate your keys

Finally, go in your Web.Config and above the set the tags.

Setting the keys in web.config

z

1

Put Code in and generate machine key from this link

http://www.eggheadcafe.com/articles/GenerateMachineKey/GenerateMachineKey.aspx

Pankil Agrawal
  • 101
  • 1
  • 1
  • 11