Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

machine.config appSettings are null

In my machine.config file I have the following

<configuration>
    ....
    <appSettings>
        <add key="key" value="value"/>
    </appSettings>
</configuration>

I am trying to retrieve it on an asp page by using

ConfigurationManager.AppSettings["key"];

and it returns null every time.

like image 846
harryovers Avatar asked Dec 08 '11 13:12

harryovers


1 Answers

You probably put it in the wrong machine.config. Remember that there is the same machine.config for .NET 2.0 and 3.5 as they both target CLR 2.0 (c:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\) and a separate machine.config for .NET 4.0 (c:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\).

Also remember that if you are running a 64 bit OS the folders are c:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG\ and c:\Windows\Microsoft.NET\Framework64\v4.0.30319\CONFIG\ respectively. So make sure you have put the key in the correct machine.config that correspond to the framework version you are targeting in your ASP.NET application as well as the x86 or x64 bit.

So you get a machine.config per CLR version and bitness (no idea if such word exists).

like image 109
Darin Dimitrov Avatar answered Oct 05 '22 03:10

Darin Dimitrov