C# machine.config appSettings为空

C# machine.config appSettings为空,c#,asp.net,.net,machine.config,C#,Asp.net,.net,Machine.config,在machine.config文件中,我有以下内容 <configuration> .... <appSettings> <add key="key" value="value"/> </appSettings> </configuration> 并且每次都返回null。您可能将其放在了错误的machine.config中。请记住,.NET 2.0和3.5的machine.config与CLR

在machine.config文件中,我有以下内容

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

并且每次都返回null。

您可能将其放在了错误的machine.config中。请记住,.NET 2.0和3.5的machine.config与CLR 2.0的machine.config是相同的(
c:\Windows\Microsoft.NET\Framework\v2.0.50727\config\
),而.NET 4.0的machine.config是单独的(
c:\Windows\Microsoft.NET\Framework\v4.0.30319\config\

还请记住,如果您运行的是64位操作系统,则文件夹分别为
c:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG\
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\CONFIG\
。因此,请确保已将密钥放入正确的machine.config中,对应于ASP.NET应用程序中的目标框架版本以及x86或x64位


因此,您可以根据CLR版本和比特数获得machine.config(不知道是否存在这样的词)。

您指的是web.config?您是否在其他地方有
clear
节点?如果您在64位环境中,则有两个
machine.config
文件。一个用于Framework64,一个用于Framework。确保它在正确的一个,或两者中。@vcsjones你的权利,那就解决了:)@harryovers太好了,Darin写下了完整的细节。这要归功于他。我不相信3.5中有machine.config,因为它是在运行时生成的。@vcsjones,不,.NET3.5中没有单独的machine.config。它与.NET2.0相同。我将更新我的答案,因为它令人困惑。
ConfigurationManager.AppSettings["key"];