简体   繁体   中英

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.

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).

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