【发布时间】:2018-12-20 12:03:58
【问题描述】:
我在 web.config 文件中有以下节点
<Properties>
<Property Name="ConnectionString" Value="Data Source=testdb;User Id=scpan;password=testp@123;Persist Security Info=false"/>
</Properties>
我正在尝试使用System.Configuration.ConfigurationManager 访问相同的内容,但无法访问“ConnectionString”标签。怎么做?
我正在尝试下面的代码,但它也没有给我结果
var section = (XmlElement)ConfigurationManager.GetSection("Resource");
if (section.GetElementsByTagName("ConnectionString").Count > 0)
{
XmlElement element = (XmlElement)section.GetElementsByTagName("ConnectionString").Item(0);
var fieldValue = element.Attributes["value"].Value;
}
这里有什么问题?
【问题讨论】:
-
@mjwills 我更新了我的帖子
标签: c# asp.net .net configuration