【Core】.NET Core中读取App.config配置文件
1.项目中添加App.config文件

因为.NET Core的项目本质是控制台应用,所以ConfigurationManager的API会去默认读取app.config配置文件,而不是web.config配置文件。
2.如果是asp.net迁移过来的配置文件,去除config中和需要的配置无关的内容,主要是<system.web>、 <system.webServer>、<system.codedom>等典型asp.net标签。
<?xml version="1.0" encoding="utf-8"?>
<configuration> <!-- To customize the asp.net core module uncomment and edit the following section.
For more info see https://go.microsoft.com/fwlink/?linkid=838655 -->
<!--
<system.webServer>
<handlers>
<remove name="aspNetCore"/>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
--> <appSettings>
<add key="Email" value="1037134@qq.com" />
</appSettings> <connectionStrings>
<add name="TestCon" connectionString="Data Source=.;Initial Catalog=OWNDB;user id=sa;pwd=123456" />
</connectionStrings> </configuration>
3.引入【 System.Configuration.ConfigurationManager 】NUGET包

4.读取
var email = System.Configuration.ConfigurationManager.AppSettings["Email"]; var conn = System.Configuration.ConfigurationManager.ConnectionStrings["TestCon"];
【Core】.NET Core中读取App.config配置文件的更多相关文章
- C# 读取app.config配置文件 节点键值,提示 "配置系统未能初始化" 错误的解决方案
新建C#项目,在app.config中添加了appSettings项,运行时出现"配置系统未能初始化"的错误,MSDN里写到,如果配置文件中包含 configSections 元素 ...
- winform中读取App.config中数据连接字符串
1.首先要在工程引用中导入System.Configuration.dll文件的引用. 2.通过System.Configuration.ConfigurationManager.Connection ...
- C# 读取app.config配置文件节点键值,提示"配置系统未能初始化" 错误的解决方案
MSDN里写到, 如果配置文件中包含 configSections 元素,则 configSections 元素必须是 configuration 元素的第一个子元素. 将自己添加的appSettin ...
- 读取app.config配置文件信息
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup& ...
- C# 读写App.config配置文件
一.C#项目中添加App.config配置文件 在控制台程序中,默认会有一个App.config配置文件,如果不小心删除掉,或者其他程序需要配置文件,可以通过添加得到. 添加步骤:右键项目名称,选择“ ...
- C# 读App.config配置文件[2]: .Net Core框架
C# 读App.config配置文件[1]:.Net Framework框架 C# 读App.config配置文件[2]: .Net Core框架 网上都是.net framework读取配置文件的方 ...
- C#中动态读写App.config配置文件
转自:http://blog.csdn.net/taoyinzhou/article/details/1906996 app.config 修改后,如果使用cofnigurationManager立即 ...
- 如何在ASP.NET Core自定义中间件中读取Request.Body和Response.Body的内容?
原文:如何在ASP.NET Core自定义中间件中读取Request.Body和Response.Body的内容? 文章名称: 如何在ASP.NET Core自定义中间件读取Request.Body和 ...
- [转]WinForm和WebForm下读取app.config web.config 中邮件配置的方法
本文转自:http://blog.csdn.net/jinbinhan/article/details/1598386 1. 在WinForm下读取 App.config中的邮件配置语句如下: Con ...
随机推荐
- MySQL数据库(查询语句)
用户 角色 权限 select * from students1:查询这个表里的数据 select ssex from students1:在这个表里面查询ssex(性别) select dist ...
- Python 学习笔记1 安装和IDE
前面的话 现在随着互联网的快速发展,对测试人员的代码要求也越来越高.有种逐步往全栈开发人员发展的趋势. 越来越多的手工测试被自动化取代. 对于测试人员,学习一门开发语言迫在眉睫. C#, JAVA, ...
- Memcache&Redis
Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.减少数据库读取次数来提高网站速度 先在一台机器安装memcache 然后使用Python 安装pip3 i ...
- (备忘)怎么去除WinRAR弹窗广告?
1.在WinRAR的安装目录下新建一个记事本,命名为“rarreg.key”. 2.打开记事本,将一下内容复制进去. RAR registration data Federal Agency for ...
- Jedis简介
实际开发中,我们需要用Redis的连接工具连接Redis然后操作Redis, 对于主流语言,Redis都提供了对应的客户端: https://redis.io/clients https://redi ...
- OC 使用CIFilter添加图片
+(UIImage *)createInviteImgWithUserCodeStr:(NSString *)userCode{ userCode = [NSString stringWithForm ...
- ubuntu 使用dpkg手动安装deb包时发生循环依赖的解决办法
将循环依赖的所有包放到同一个命令行里一起安装,如: sudo dpkg -i libnss3-nssdb_3.28.4-0ubuntu0.14.04.4_all.deb libnss3_3.28.4- ...
- ZooKeeper之service discovery
Zookeeper整体介绍 ZooKeeper is a centralized service for maintaining configuration information, naming, ...
- python中Hadamard product和matrix product的区分
先简单说一下Hadamard product: (参照维基百科:https://en.wikipedia.org/wiki/Hadamard_product_(matrices)) 而matrix ...
- Oracle 11g R2创建数据库之DBCA静默方式
通常创建Oracle数据库都是通过DBCA(Database Configuration Assistant)工具完成的,DBCA工具可以通过两种方式完成建库任务,即图形界面方式和静默命令行方式.既然 ...