.Net Core 读取配置文件
2017-07-24 15:37
302 查看
话不多说直接上代码:
public static class MengTConfig { static IConfigurationRoot _MT_Configuration { get; } static IConfigurationSection _MT_AppSetting; static MengTConfig() { var builder = new ConfigurationBuilder() .SetBasePath(AppContext.BaseDirectory) .AddJsonFile("_config/MengT.json", optional: true, reloadOnChange: true); _MT_Configuration = builder.Build(); _MT_AppSetting = _MT_Configuration.GetSection("AppSettings"); } /// <summary> /// 通过[Key]获取数据库连接字符串 /// </summary> /// <param name="_key">Key</param> /// <returns></returns> public static string GetConnectionString(string _key) { return _MT_Configuration.GetConnectionString(_key); } /// <summary> /// 通过[Key]获取配置信息 /// </summary> /// <param name="_key">Key</param> /// <returns></returns> public static string GetAppSetting(string _key) { return _MT_AppSetting[_key]; } }
相关文章推荐
- NET Core开发-读取配置文件Configuration
- 使用.net core读取Json文件配置
- .net core 2.0 读取配置文件
- .net core 读取配置文件
- .NET Core类库中读取配置文件
- .NET Core简单读取json配置文件
- .NET Core 中读取appsettings.json配置文件的方法
- [.NET Core] 简单读取 json 配置文件
- .Net Core从命令行读取配置文件
- .net core 学习笔记(5)-配置文件读取
- .Net Core配置文件读取整理
- .NET Core 读取配置文件
- 使用VS Code开发.Net Core 2.0 MVC Web应用程序教程之三(配置文件读取)
- .Net Core 读取配置文件 appsettings.json
- java 读取 properties 配置文件 备忘
- APP自动化框架学习:读取配置文件,并判断定位方式
- Springboot 之 自定义配置文件及读取配置文件注意:配置文件中的字符串不要有下划线 .配置中 key不能带下划线,value可以(下划线的坑,坑了我两天..特此纪念)
- Python读取ini配置文件
- Spring 使用配置文件读取jdbc.properties
- Python Configparser模块读取、写入配置文件