我在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;
}
这是怎么了?
答案 0 :(得分:0)
您需要像这样将连接字符串放在connectionStrings
的{{1}}部分的configuration
部分
web.config