3

Is there an easier way of doing the lines below?

var doc = new XmlDocument();
doc.Load("../../../MyWebSite/Web.config");
var mysqlconn = doc.DocumentElement.SelectSingleNode(
    "//appSettings//add[@key='mysqlconn']").Attributes["value"].Value;
4

1 回答 1

11
System.Configuration.ConfigurationManager.AppSettings["mysqlconn"]

应该给你价值。您可能希望将它们移动到一个<connectionStrings />部分中,您可以使用它:

System.Configuration.ConfigurationManager.ConnectionStrings["mysqlconn"]
                                                                .ConnectionString
于 2013-03-09T23:09:05.660 回答