Asp.net-读取App.config

读取App.config

1.添加引用 System.Configuration.dll

2.using System.Configuration;

3.ConfigurationManager.AppSettings[key]

<!-- xml -->
<appSettings>
    <add key="ref" value="1" />
    <add key="dll" value="2" />
</appSettings>
var dll = ConfigurationManager.AppSettings["dll"];//1
var @ref = ConfigurationManager.AppSettings["ref"];//2

读取数据库连接字符串

var str = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
上一篇:为什么.NET Core项目中,在appsettings.json配置文件中定义的配置项,会出现乱码


下一篇:Delete field (column) from a SharePoint list Using C#(CSOM)