我在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