machine.config appSettings are null

空扰寡人 提交于 2019-12-19 00:42:35

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/8431709/machine-config-appsettings-are-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!