我在web.config文件中得到了下面的示例代码。如何从web.config中的自定义节中读取值
<configuration>
<configSections>
<section name="secureAppSettings" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<secureAppSettings>
<add key="userName" value="username"/>
<add key="userPassword" value="password"/>
</secureAppSettings>
</configuration>
我的新节secureAppSettings
被解密,并且里面有两个密钥。
现在在我的代码,我想访问这些关键的东西象下面这样:
string userName = System.Configuration.ConfigurationManager.secureAppSettings["userName"];
string userPassword = System.Configuration.ConfigurationManager.secureAppSettings["userPassword"];
但它返回null
这些字段。
如何获取值?
最有用和一直在努力解决这是一个在我看来: http://stackoverflow.com/a/28600293/4250041 – benraay 2017-03-07 13:32:07