Machine.config appSettings - null

In my machine.config file, I have the following

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

I am trying to get it on an asp page using

 ConfigurationManager.AppSettings["key"]; 

and each time it returns null.

+6
source share
1 answer

You may have specified the wrong machine.config file. Remember that the same machine.config file exists for .NET 2.0 and 3.5, as both are for 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 use a 64-bit OS, then the folders c:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG\ and c:\Windows\Microsoft.NET\Framework64\v4.0.30319\CONFIG\ respectively . Therefore, make sure that you put the key in the correct machine.config file, which corresponds to the version of the framework version that you are targeting the ASP.NET application, as well as the x86 or x64 bit.

So, you get the machine.config file for the CLR version and bitness (I don’t know if such a word exists).

+18
source

Source: https://habr.com/ru/post/903374/


All Articles